I thought of two ways:
- PHP code is converted directly to JS code
- PHP engine for front-end browsers
is it possible to achieve these two methods, and what is the difficulty?
I thought of two ways:
is it possible to achieve these two methods, and what is the difficulty?
solution 1: feasible, equivalent to writing a HTML/JS compiler or parser, PHP is the source code, JS/HTML is the compiled code, and then directly output the compiled code to the front end. The difficulty is to implement a parser / compiler
solution 2: the front-end browser uses the engine of PHP. In theory, it is feasible, but in reality, JS already dominates the world. In doing so, there will be a lot of front-ends wanting to beat you.
the first solution is possible. You can refer to Typescript
to write html tags directly outside php? >. Or print
and directly use php's EOF to express the front-end code and then directly echo it