1
切割的方向也有我喜歡的字符串:PHP:從字符串
/home/kamal/public_html/clients/book/wp-content/uploads/wpcf7_uploads/1983322598/k.jpg
我需要得到的只有
wp-content/uploads/wpcf7_uploads/1983322598/k.jpg
怎麼能這樣做?
切割的方向也有我喜歡的字符串:PHP:從字符串
/home/kamal/public_html/clients/book/wp-content/uploads/wpcf7_uploads/1983322598/k.jpg
我需要得到的只有
wp-content/uploads/wpcf7_uploads/1983322598/k.jpg
怎麼能這樣做?
$string = "/home/kamal/public_html/clients/book/wp-content/uploads/wpcf7_uploads/1983322598/k.jpg";
$exploded_string = explode("/", $string);
//$exploded_string is now an array of: home, kamal, public_html.... ...k.jpg
$n = array_search("wp-content", $exploded_string);
//$n is now the index of "wp-content" in the $exploded_string array
$new_path = array_slice($exploded_string, $n);
$new_path = implode("/", $new_path);
echo $new_path;
是'/家庭/卡邁勒/的public_html /客戶機/電子書/'在每串一樣的嗎?一個簡單的方法是'$ string = str_replace('/ home/kamal/public_html/clients/book /','',$ string);' – samlev