I have a bunch of javascript files I need to parse via PHP (I don’t want to push them to the browser; I want to do this fully in the backend), and they all contain a variable declaration, for example (actual content of one of the js files):
var x = '<html><div class="foo">blocks of text</div></html>';
Basically they all enclose html within single quotes, and the variable is always the same (x in this case). What’s the best way to extract everything inside the single quotes into a PHP variable?
edit: there’s extra code at the end of each file generated (I am not generating the files by the way, it’s done by a 3rd party):
if(navigator.userAgent.indexOf('MSIE 7')>-1){ x = x.replace(/([^>])<(\/?)span/g,'$1<wbr/><$2span'); }; jsonp_PageLoaded(1,0,x);
Figured this out on my own. Here’s the code using PHP: