$价值我想筛选值如何筛选在PHP
例如: 112
是01:12
从脚本
$duration = get_post_meta($post->ID, 'TMDB_Runtime', true);
if (! empty($duration)) {
echo '<div class="gmr-duration-item" property="duration">' . $duration . __(' <a class="fa fa-clock-o" aria-hidden="true"></a>','movies') . '</div>';
我试着使用SUBSTR和str_replace函数,并把它into function.php
<?php
$text = '$duration';
$text = substr($text, 0, 3);
echo $text =str_replace("1","01:", $text);
?>
但是总是显示解析错误。
谢谢老兄:)。这是真正的方法,它的工作,但是...''持续时间'它并不总是'112'值,我的意思是,从$持续时间(eee)获得价值并将其过滤到(ee:ee) –
但它会一直有1,2,3或4个数字是一个时间。所以你可以首先检查字符串长度,然后有一个switch语句,如果它是1,2,3或4,应用0:#或#:#等等 – clearshot66