Home > Backend Development > PHP Tutorial > 麻烦帮我看看这个该怎么正则匹配

麻烦帮我看看这个该怎么正则匹配

WBOY
Release: 2016-06-23 13:10:48
Original
755 people have browsed it

1.
http://abc/innd/ffdss/Jack
2.
http://abc/innd/ffdss/dfdf/ssss/Peter
3.
http://abc/ffdss/Sam

麻烦大神用一句正则匹配末尾把这三个网址最后的Jack、Peter和Sam匹配出来

好久不用正则忘记了- -


回复讨论(解决方案)

//可以不需要正则$url = 'http://abc/innd/ffdss/Jack';echo substr($url, strrpos($url, '/')+1);
Copy after login
Copy after login

//可以不需要正则$url = 'http://abc/innd/ffdss/Jack';echo substr($url, strrpos($url, '/')+1);
Copy after login
Copy after login



谢谢不过我们老师说要用正则,能不能教一下正则该怎么做

$s = 'http://abc/innd/ffdss/Jack';preg_match('#/([^/]+)$#', $s, $m);echo $m[1];
Copy after login

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template