0
A
回答
8
<?php
$url = 'http://itutormaths.hub/home/hub/6/hello/world';
$pathParts = explode('/', parse_url($url, PHP_URL_PATH));
$lastParts = array(array_pop($pathParts), array_pop($pathParts));
var_dump($lastParts);
+0
這只是一段性感的代碼。乾杯隊友 – user1219572 2012-03-15 18:14:56
0
$url='http://itutormaths.hub/home/hub/6/hello/world';
$res=explode("6/",$url);
$res1=$res[1];
$res=explode("/",$res1);
$res1=$res[0];
print_r($res1);
$res2=$res[1];
print_r($res2);
使用爆炸功能
0
<?php
//returns all occurrences of a string
function strpos_recursive($haystack, $needle, $offset = 0, &$results = array()) {
$offset = strpos($haystack, $needle, $offset);
if($offset === false) {
return $results;
} else {
$results[] = $offset;
return strpos_recursive($haystack, $needle, ($offset + 1), $results);
}
}
$url = "http://itutormaths.hub/home/hub/6/hello/world";
$positions = strpos_recursive($url,"/");
//World (ie the 7th occurence of /)
echo substr($url, $positions[6]+1)."<br />";
//hello (ie the string between the 6th and 7th occurence of /)
echo substr($url, $positions[5]+1,($positions[6]-$positions[5]-1))."<br />";
?>
或檢查出preg_mactch_all(php.net/manual/en/function.preg-match-all.php)
相關問題
- 1. 獲取URL路徑的最後部分
- 2. jQuery獲取URL的最後部分
- 3. 如何在MongoDB中獲取url的最後部分?
- 4. 如何從PHP中的URL字符串獲取最後一部分?
- 5. Php獲取url的最後部分並刪除/
- 6. 如何獲取URL的基礎(最後部分)?
- 7. URL的最後一部分
- 8. PHP獲取部分url的值
- 9. 使用PHP獲取URL的一部分
- 10. 如何提取PHP中的最後一部分?
- 11. AngularJS - 如何獲取URL的最後部分,忽略任何GET參數?
- 12. 如何使用jQuery獲取url的最後兩個字符?
- 13. 如何獲取URL的一部分?
- 14. 如何獲取URL的特定部分?
- 15. 使用jQuery獲取url的最後部分
- 16. 獲取一個URL的最後一部分作爲GET參數
- 17. 如何在Javascript中獲取字符串的最後部分
- 18. 獲取URL的最新部分作爲輸入到PHP文件
- 19. 獲取部分URL
- 20. 獲取URI的最後部分
- 21. 如何使用正則表達式獲取songkick URL的最後部分?
- 22. 點擊按鈕後獲取url部分
- 23. PHP - 如何獲取URL字符串的最後一段
- 24. 如何使用PHP獲取url的不同部分?
- 25. 如何拆分字符串並獲取最後一部分?
- 26. 如何使用jquery獲取部分url?
- 27. 獲取URL的部分window.location
- 28. 獲取包含php文件的問號(?)後的url參數或URL的部分
- 29. 如何獲取此文件路徑的最後部分?
- 30. 如何獲取字符串的最後部分?
那你試試? – Evert 2012-03-15 17:21:17
從這裏開始:http://us3.php.net/manual/en/function.parse-url.php – 2012-03-15 17:22:11
沒什麼,因爲我不知道如何:( – user1219572 2012-03-15 17:22:13