Below the php regular string 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!
Reply to discussion (solution)
$a = '../post/luoji/soft/aaa.chm';$a=pathinfo($a,PATHINFO_BASENAME);echo $a;
$ Str = "../post/luoji/aaa. chm ";
$ Str = preg_split ("/[\ s, \/!] +/", $ Str );
$ Len = sizeof ($ str );
$ Res = $ str [$ len-1];
Echo $ res;
$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);
......