Optional & nbsp; php regular string
Below is the string
$ A = '../post/luoji/soft/aaa. chm'
$ B = '../post/luoji/bbb.txt'
$ C = 'post/luoji/c.rar'
$ D = '../luo/p/d.zip'
$ E = '../lio/p/a.tar.gz'
$ F = '../pp/tt/p/lp/p/tttt/p/t. rpm'
The request is as follows:
$ A = 'AAA. chm'
$ B = 'bbb.txt'
$ C = 'c.rar'
$ D = 'd.zip'
$ E = 'a.tar.gz'
$ F = 'T. rpm'
That is, no matter how long the string is, you only need to get the final name.
I will write it like this
$ Str = "../post/luoji/aaa. chm ";
$ Str = preg_split ("/[\ s, \/!] +/", $ Str );
Echo'
'; Print_r ($ str [3]);
Cannot be dynamically obtained
How can I use regular expressions? Thank you!
------ Solution --------------------
$a = '../post/luoji/soft/aaa.chm';
$a=pathinfo($a,PATHINFO_BASENAME);
echo $a;
------ Solution --------------------
$a = '../post/luoji/soft/aaa.chm';
preg_match('#[^/]+$#', $a, $r);
echo $r[0];
$a = '../post/luoji/soft/aaa.chm';
$a = preg_split('#/#', $a);
echo array_pop($a);
$a = '../post/luoji/soft/aaa.chm';
$a = preg_split('#/#', $a);
echo end($a);
$a = '../post/luoji/soft/aaa.chm';
echo basename($a);
......