background image
*/
$url
= 'http://www.test.com/news/detail/2012/11/26/9778.html';
$baseName
=
strrchr
(
$url
, '/');
//输出:/9778.html
echo
trim
(
$baseName
, '/');
//输出:9778.html
(3)strpos($str, $need) 在字符串$str 中查找$need 首次出现的位置,返回
这个位置值
=>不区分大小写时用 stripos()
(4)strrpos($str, $need) 在字符串$str 中查找$need 最后一次出现的位置,
返回这个位置
=>不区分大小写时用 strripos()
1
/**
2
* strpos($str, $need [,int $offset])
3
* @param string $str 要操作的字符串
4
* @param string $need 要被搜索的字符
5
* @param int $offset 搜索的起始位置(即字符串哪个字符开始算起)
6
* @description:搜索$need 在$str 中首次出现的位置
7
* 相关函数:stripos()不区分大小写,strrpos()最后一次出现的位置
8
*/
9
$path
= 'var/cache/tpl/20121126.php';
10
$root_location
=
strpos
(
$path
, '/');
11
var_dump
(
$root_location
);
//输出 3
12
var_dump
(
substr
(
$path
, 0,
$root_location
));
//输出 var
13
$filename_location
=
strrpos
(
$path
, '/');
14
var_dump
(
$filename_location
);
//输出 13
15
var_dump
(
substr
(
$path
, 0,
$filename_location
));
//输出 var/cache/tpl
16
var_dump
(
substr
(
$path
,
$filename_location
,
strlen
(
$path
)));
//输出/20121126.
php
(5)strpbrk($str, $charlist) 查找字符集$charlist 的任意一个字符在$str 首
次出现的位置开始到结尾的子串