0

I want RegEx in php that find value of js variable in my html page. Like this:

varName = "http://sample.com";
1
  • 1
    So, you want to extract the value of a JavaScript variable in an HTML page stored in a PHP variable? Commented May 16, 2012 at 15:40

1 Answer 1

3

Something like that... but it could be extremely more complicated with the complexity of the js code

<?
$varname = "varName";
preg_match('/'.$varname.'\s*?=\s*?(.*)\s*?(;|$)/msU',$html,$matches);

if(count($matches>1)) {
    print($matches[1]);
}


?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.