你好,我試圖讓PHP返回一個文件名,並返回字符串作爲將被一個JavaScript插件使用的rel標籤的一部分。php文件名達到特定字符
我需要添加一些PHP腳本返回的文件名字符串到第二hyphon: 到目前爲止,我已經
<?php
$filename = basename (get_attached_file(get_post_thumbnail_id()));
?>
<?php echo pathinfo($filename, PATHINFO_FILENAME); ?>
返回
tulip-367-011
文件名是tulip-367-011.jpg
我怎麼得到它返回tulip-367
您好我試過
<?php
$filename = basename (get_attached_file(get_post_thumbnail_id()));
?>
<?php echo $file_parts = explode('-', basename($filename));
array_pop($file_parts); // Remove the last segment
$split_name = implode('-', $file_parts);
?>
它返回數組 - 不是一個時間!那真的會讓我輕笑,我已經在這個星期呆過了一個星期了。再次感謝幫助,我會繼續努力。我不是一個很好的程序員,所以請隨時嘲笑我的愚蠢。阿薩
我試着
$file_parts = explode('-', basename($filename));
array_pop($file_parts); // Remove the last segment
$split_name = implode('-', $file_parts);
而且它也表示數組。再次感謝你的幫助。
如果您還需要從文件中刪除幾個字符http://php.net/manual/en/function.substr.php可能會有所幫助 – Tim 2012-08-13 18:45:48
解決它大,非常感謝。作爲一個 – 2012-08-14 09:40:18