Reputation: 727
i have json
{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}
How can i print like
http://www.google.com/
http://www.facebook.com/
http://www.wordpress.com/
Upvotes: 2
Views: 3811
Reputation: 61935
Start with real JSON, representing an array of values.
$json = '["http://www.google.com/","http://www.facebook.com/",".."]';
Then use json_decode
.
$arr = json_decode($json);
print_r($arr);
Upvotes: 3
Reputation: 9635
you can use this function
function getUrls($string) {
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $matches);
//return (array_reverse($matches[0]));
return ($matches[0]);
}
like this
$json_str = '{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}';
$arr = getUrls($json_str);
echo "<pre>";
print_r($arr);
OUTPUT :
Array
(
[0] => http://www.google.com/
[1] => http://www.facebook.com/
[2] => http://www.wordpress.com/
)
Upvotes: 3
Reputation: 2910
The lame answer :)
$json = '{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}';
$json = str_replace(array('{', '}'), array('[',']'), $json);
print_r(json_decode($json));
Upvotes: 2
Reputation: 906
look at this sample code in php
<?php
$jsonData = '{ "user":"John", "age":22, "country":"United States" }';
$phpArray = json_decode($jsonData);
print_r($phpArray);
foreach ($phpArray as $key => $value) {
echo "<p>$key | $value</p>";
}
?>
Upvotes: 2