Home  >  Article  >  Backend Development  >  怎么获取url中的某段字符串

怎么获取url中的某段字符串

WBOY
WBOYOriginal
2016-06-13 10:57:38757browse

如何获取url中的某段字符串
比如url是: http://localhost/A/B/C.php
我想获取到B这个字符串的值,
请问如何搞定?(最好有代码)
谢谢!

------解决方案--------------------
哦,改一下
$s='http://localhost/A/B/C.php';
$arr=explode('/',pathinfo($s,PATHINFO_DIRNAME ));
echo $arr[count($arr)-1];
------解决方案--------------------
$s = 'http://localhost/A/B/C.php';
$t = explode('/', $s);
echo current(array_slice($t, -2, 1));//B
------解决方案--------------------
echo basename(dirname('http://localhost/A/B/C.php'));

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn