Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode JSON values without key?

Tags:

json

php

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/
like image 626
Liju Avatar asked Mar 27 '26 18:03

Liju


1 Answers

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/
)
like image 71
Satish Sharma Avatar answered Mar 29 '26 07:03

Satish Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!