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. 如何从PHP中的URL字符串获取最后一部分?
- 2. URL的最后一部分
- 3. 如何使用jQuery获取url的最后两个字符?
- 4. 如何在Javascript中获取字符串的最后部分
- 5. 提取URL域名,并获得最后一部分
- 6. 如何拆分字符串并获取最后一部分?
- 7. 如何使用jquery获取部分url?
- 8. 获取URL的部分window.location
- 9. 获取包含php文件的问号(?)后的url参数或URL的部分
- 10. 如何获取字符串的最后部分?
- 11. 如何获取网址的最后一部分AngularJS
- 12. 通过url获取url的特定部分后的值
- 13. 如何获得URL中的锚点部分#在php中
- 14. 如何获得通过分隔的字符串的最后两个部分,
- 15. 如何获得c#中的URL部分?
- 16. 获取主URL部分
- 17. 每次爆炸url的最后部分
- 18. 如何在纯PHP中遵循HTTP重定向后获取最终的URL?
- 19. 如何获取当前URL,然后得到最后的话
- 20. 如何提取PHP中的一部分URL以移除特定部分?
- 21. 如何获取URL中的最后一个路径?
- 22. 如何获取PHP中的完整URL?
- 23. 消除URL字符串的最后一部分在PHP
- 24. 如何获取分页URL
- 25. 如何在silverlight中获取当前URL的某个部分?
- 26. Rails,获取URL/modelstuff/31的一部分---如何获得31?
- 27. PHP - 获取CouchDB中的最后一行
- 28. Google应用引擎如何在获取请求中获取url的一部分?
- 29. 获取java中列表元素的最后一部分
- 30. 如何使用laravel 5.2获取刀片文件(HTML)中的url的最后部分?
那你试试? – 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