Why is my regular expression incorrect $ url = "http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml"; my goal is to retrieve 039bf460-2ea why is my regular expression incorrect
$ Url = "http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml ";
My goal is to retrieve 039bf460-2eaa-4098-89e2-fa07512a8588
Written in this way
// Obtain the video id
Preg_match ('/\/(.*)?. Shtml/', $ url, $ videoID );
Print_r ($ videoID );
Why not? Please advise. Thank you.
------ Solution --------------------
\/(.*)?. The shtml regular expression indicates a string of characters starting from/and ending with shtml. if you want to obtain it, use the following method:
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";
$path = pathinfo($url);
var_dump($path['filename'])
------ Solution --------------------
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";
preg_match('/([^\/]*?).shtml/',$url, $videoID);
print_r($videoID);
Array
(
[0] => 039bf460-2eaa-4098-89e2-fa07512a8588.shtml
[1] => 039bf460-2eaa-4098-89e2-fa07512a8588
)
------ Solution --------------------
Preg_match ('/\/(.*?) \. Shtml/', $ url, $ videoID );
------ Solution --------------------
Echo basename ($ url, ". shtml ");