$價值我想篩選值如何篩選在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