views:

105

answers:

1

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");
+3  A: 

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.

cazlab
I knew jParser library. Yes, it's more like what I need but I would like to test and another parser. Thanks for the answer.
Stefan K