PHP截取特定字符前面或后面的内容

1.截取特定字符前的内容

$test = '/home/test/test.txt';
$result = substr($test,0,strrpos($test,"/"));
echo $result;

输出:/home/test

2.截取特定字符后的内容

$number = '/home/test/test.txt';
$result = substr($number,strripos($number,"/")+1);
echo $result;

输出:test.txt

你可能感兴趣的:(PHP,php)