我的英語不是很好。對不起。
我想從我的 URL 字串中回顯 post_12345678:
總想回聲一件事結束前。
<?php
$url_string = "https://localhost/categories/post_12345678/a25d48aff";
echo preg_replace('/[\^categories/].*?[\/]/' , '', $string );
?>
- a25d48aff 和 post_12345678 是變數
uj5u.com熱心網友回復:
有了parse_url,這個任務就變得簡單多了。只需提取之路,關鍵值和訪問使用的倒數第二個鍵explode和array_reverse。
<?php
$url_string = "https://localhost/categories/post_12345678/a25d48aff";
$str = trim(parse_url($url_string)['path'], '/');
echo array_reverse(explode("/", $str))[1];
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/387580.html
