doujubeng2942 2012-07-24 19:54
浏览 55
已采纳

substr不工作? PHP

Unfortunately I can't point you to a live example. But I've got a form that submits a bunch of data to the database.

I retrieve the 'date' field with

genesis_custom_field('date')

and the output date is "mm/dd/yyyy" e.g., 02/19/2012

so shouldn't

echo substr(genesis_custom_field('date'), 0, 2) . '<-M<br />'

output "02"

instead, it's outputting the full date format, "02/19/2012".

INTENTS AND PURPOSES

for intents and purposes, here's the code sample.

// The Query
$reviews_query = new WP_Query('showposts=1');

// The Loop
while ( $reviews_query->have_posts() ) : $reviews_query->the_post();

echo substr(genesis_custom_field('date'), 0, 2) . '<-M<br />';

endwhile;
// Reset Post Data
wp_reset_postdata();

with the intended output of

02<-M

but I'm getting

02/19/2012<-M
  • 写回答

1条回答 默认 最新

  • douxi8119 2012-07-24 20:02
    关注

    The function genesis_custom_field actually echoes the value rather than return it which is why substr isn't working. You are basically calling substr on a null value.

    Instead use the function genesis_get_custom_field if you want the value returned so you can modify it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计