I want to get the specific content from script
tags from a web page.
Here is HTML page.
<html>
<head>
<title></title>
<script>
//some other srcipt code
</script>
</head>
<body>
<script>
//some other srcipt code
</script>
<!-- some other html code -->
<script>
var abc = {"asld":"asdjk","thisone":"https:\/\/www.example.com\/$N.jpg|#1000#M$M#JSuL8|1000#M$M#fW4EC0jcOl8kUY_QBZbOASsF8t0","user_gender":"m"};
</script>
</body>
</html>
I want to get only this value fW4EC0jcOl8kUY_QBZbOASsF8t0
which is in the last attribute of thisone
in a script variable var abc
.
Can I do this with PHP HTML DOM
. If no then how can I do
You can easily get it using the regex
"thisone":".*#(.*)",
Assuming, the webpage is http://example.com,
$data = file_get_contents('http://example.com');
preg_match_all("/\"thisone\":\".*#(.*)\",/", $data, $output);
echo $output[1][0]; // prints fW4EC0jcOl8kUY_QBZbOASsF8t0
Hope that helps!