0

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

2
  • 1
    What kind of string is that? Where does it come from? I don't think this needs a Regex Commented Dec 27, 2010 at 16:34
  • 1
    Also for what you were doing wrong: the escaping. It's \ backslash, not /. Commented Dec 27, 2010 at 16:44

3 Answers 3

4

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];

?>
Sign up to request clarification or add additional context in comments.

Comments

1
<?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];
?>

Comments

0

You may use that regex

http.+\....(?=",".+)

That will work for all 3 letters extensions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.