I'm trying to parse some HTML with Xpath but am finding out the the links I want to get are generated by some javascript and not using just a normal a anchor. The javascript is as follows:
<script type="text/javascript">
var Hyperurl="ab5";
var Hyperlink="46439157";
</script>
Now, I've used XPath to grab the script code via:
$xpath->query('//script[contains(.,"Hyper")]');
Which returns:
var Hyperurl="ab5";var Hyperlink="46439157";
My question is. How do I get this data into an array much like parse_url or the like? Should I just preg_match_all the variable storing the string? If so, what regex would I use? Or is there a better way to parse and grab the data I want?
Thanks in advance!
You could try:
preg_match_all('/"(.*?)"/', $variables, $array);
I think your variables would then be $array[1] and $array[2].
You could use this
preg_match_all('/var\s+(\w+)\s*=\s*(["\']?)(.*?)\2;/i', $js, $matches);
$matches[1]
will contain the variable names, and $matches[3]
will contain their values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With