I have a $source
var which I get with curl and contains the following commented out string
//"url":"http://lh5.ggpht.com/_EpgGIto9934/TKXKqAw7uFI/AAAAAAAAGrM/PrQiCNyUdEo/8827.jpg","
$regex = "!url/"/:/"(.*)8827/.jpg!U";
preg_match_all($regex, $source, $res);
var_dump($res);
I want to get the http://.....jpg
address What am I doing wrong? Thanks
That looks like json. If that's the case you won't need regular expressions for that. You can just use json_decode
<?php
$s = "//\"url\":\"http://lh5.ggpht.com/_EpgGIto9934/TKXKqAw7uFI/AAAAAAAAGrM/PrQiCNyUdEo/8827.jpg\",\"";
$regex = '/http(.+)\.jpg/';
preg_match($regex, $s, $matches);
echo $matches[0];
?>
<?php
$source = '"url":"http://lh5.ggpht.com/_EpgGIto9934/TKXKqAw7uFI/AAAAAAAAGrM/PrQiCNyUdEo/8827.jpg","';
$regex = '/^.*\/([^\/]+\.jpg).*$/';
preg_match($regex, $source, $res);
print_r($res);
$jpg = $res[1];
?>
You may use that regex
http.+\....(?=",".+)
That will work for all 3 letters extensions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.