I am having trouble extracting a value from Javascript with PHP -


i received below code amongst whole lot of html fetch in php, code in script tags. having trouble using preg_match efficiently extract value of hardest27 on line.

so have variable called $html contains whole lot of html contains line below.

$("<input>").attr({name: "levelreached", value: "hardest27" }).appendto(newform);

how can php return me value of levelreached?

you may try regex on content:

"levelreached"\s*,\s*value:\s*"([^"]*)" 

group 1 contains expected value.

regex demo

sample demo source:

preg_match_all($re, $html, $matches);  foreach($matches[1] $matchgroup)     echo $matchgroup."\n"; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -