Home > Backend Development > PHP Tutorial > 小弟我的正则为何不对

小弟我的正则为何不对

WBOY
Release: 2016-06-13 11:51:51
Original
934 people have browsed it

我的正则为何不对
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";

我的目标是取出039bf460-2eaa-4098-89e2-fa07512a8588

这样写的

//取视频的id
preg_match('/\/(.*)?.shtml/',$url, $videoID);
print_r($videoID);

为何不对啊?请指教。谢谢



------解决方案--------------------
\/(.*)?.shtml这个正则表示从/开始到shtml结束的一串字符 如果你想获取可以用下面的方式:

$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";<br />$path = pathinfo($url);<br />var_dump($path['filename'])
Copy after login

------解决方案--------------------
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";<br /><br />preg_match('/([^\/]*?).shtml/',$url, $videoID);<br />print_r($videoID);<br />
Copy after login
Array
(
    [0] => 039bf460-2eaa-4098-89e2-fa07512a8588.shtml
    [1] => 039bf460-2eaa-4098-89e2-fa07512a8588
)

------解决方案--------------------
preg_match('/\/(.*?)\.shtml/',$url, $videoID);
------解决方案--------------------
echo basename($url,".shtml"); 

Related labels:
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