Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Javascript from PHP?

Tags:

javascript

php

Are there any libraries or tools specifically designed to help PHP programmers write Javascript? Essentially, converting the PHP logic into Javascript logic. For instance:

$document = new Document($html);
$myFoo = $document->getElementById("foo");
$myFoo->value = "Hello World";

Being converted into the following output:

var myFoo = document.getElementById("foo");
myFoo.value = "Hello World";

So the $html that is passed in won't initially be modified by the PHP. Instead, the PHP will convert itself into Javascript which is then appended onto the end of the $html variable to be ran when the variable it output and converted into the client-side DOM.

Of course it would be excellent if more complicated solutions could be derived too, perhaps converting objects and internal methods into javascript-objects, etc.

like image 375
Aristotle Avatar asked Jul 11 '26 12:07

Aristotle


1 Answers

Sounds like you may be looking for something like http://xajaxproject.org. However, it might be geared more towards ajax functionality.. not all javascript. I toyed with it about 2 years ago but never used it seriously. Might be worth a look.

like image 157
Mike B Avatar answered Jul 13 '26 20:07

Mike B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!