This is not another of those questions, this is about parsing and interpreting PHP in the browser with JS.
How can you run PHP in JavaScript? I am not asking about running PHP in the server and then send the resulting string to the browser as JavaScript. I am literally talking about JavaScript parsing and running PHP.
This might be useful in many places:
- An express Node.js app that has to use a PHP module.
- A small REPL for the browser that does not need a whole VM per instance. Ideal for learning PHP.
- Making a template engine for a static site constructor.
I've searched around and found php-parser and babel-preset-php, but nothing to run it. Ideally I'm looking for something like this, though I couldn't find anything through Google/SO/etc:
// No server needed, "just" Javascript parsing PHP
alert(php(`<?= "Hello world" ?>`));
If you know a better way than my own answer, please feel free to share it! I'm very curious about what the community thinks.