How to make PHP code write front end?

I thought of two ways:

  1. PHP code is converted directly to JS code
  2. PHP engine for front-end browsers

is it possible to achieve these two methods, and what is the difficulty?

Jan.28,2022

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 . Or print


and directly use php's EOF to express the front-end code and then directly echo it

Menu