I'm trying to find a JSON string inside a string, with PHP.
So if a string is entirely JSON, PHP can parse it like this:
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));
?>
But what if I have a string like
$str = 'I have a string that contains JSON like this : {"a":1,"b":2,"c":3,"d":4,"e":5} and then string continues';
How can I parse JSON from this?
Thanks !
Edit:
Thanks for all your answers. They really helped me. And I should add that in my case, the string will be in this form:
$str = 'some string and some more string [[delimiter]] json={"a":1,"b":2}';
and, I'm not the downvoter :)