Reputation: 1119
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
Upvotes: 0
Views: 161
Reputation: 9577
You may use that regex
http.+\....(?=",".+)
That will work for all 3 letters extensions.
Upvotes: 0
Reputation: 26211
<?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];
?>
Upvotes: 1
Reputation: 19203
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];
?>
Upvotes: 4