I have this html text and need to extract mydata from html to php
<script>
var mydata=[{"id":105,"i":"4.jpg"},{id":13,"i":"5.jpg"}];
//some other js code
</script>
I tried this in php:
$html = file_get_contents($url);
$js = preg_grep("/var mydata={.*}/", $html);
$js = str_replace("var mydata=", "", $js );
$sv = json_decode($js);
print_r($sv);
Nothing is extracted. What am I doing wrong please?
P.S. I found similar topic here How to get Javascript variable from an HTML page?