Question

I have to extract defined variable and function names from a js code passed as a text. Example:

$js_code = " var MyVar1 = 'val1'; \n var MyVar2 = 'val2' ; \n function MyFunc() { some code }";

Extracted:

$js_vars = array("MyVar1", "MyVar2");
$js_func = array("MyFunc");
Was it helpful?

Solution

Have you tried Aptana Jaxer? It's an HTTP/Apache javascript parser.

There's also tools like jParser: http://timwhitlock.info/jparser/ Which is a php library which parses javascript. That might be more like what you need, but only if you're using PHP server-side.

I hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top