I need PHP code to convert some PHP to JS.
- Functionality - I use common PHP functions from php.js
- syntax - ???
The problem is syntax conversion. I do not need the full PHP syntax, mind you; there is no need to support class / declaration definitions. Here is a short checklist of what needs to be converted:
- "must be" + "(string concat)
- "->" should be "." (object operator)
- "::" must be "." (class operator - not required)
Please note that the resulting code is practically independent of the PHP environment, so there is no "what if it uses the PHP class?"
I am not asking for the complete code, but only a hint in the right direction for such a conversion; I was thinking about how to use a car / engine.
If you're wondering why I click code on the user side: I need a dynamic way to change the visibility of certain elements under certain conditions. My plan is to do this without having to execute this side of the code server and have unnecessary ajax calls.
Edit: See people. I do not know how to use AJAX sounds ridiculous for you, but the world does not work on the hype and pleasant design conditions (= ajax). I just can’t allow each user to poll my server from 5 to 10 times per second just for my server to return a yes or no answer. Keep in mind that switching is asynchronous and I cannot buffer AJAX calls.
Edit 2: I am sure that what I am doing is the best way in my situation. There is no “possibly better” way, so stop posting non-constructive comments. I cannot go into the details of what I already have. Converting from PHP to JS is simply a reduction in user input; we need only one expression, and then convert it depending on what language is needed (in this particular case, from PHP to JS). The conditions for how this will work will not change regardless of whether I describe the system before the API specifications, and flooding the topic with useless (for you) document prototypes will not help at all.
In addition, for those who think that this idea arose after some dream woke up; You know that this was examined between technical development and QA, so please do not deviate from problems with a lack of design.
Edit 3: Examples (PHP source code and expected result):
- (original) - (converted)
5=="test" - 5=="test"'$'.(func(12)*10) - '$'+(func(12)*10)Fields::count()==5 - Fields.count()==5$this->id==5 - this.id==5
In the last example, do not worry about the context / area, this is correct. Also note that expressions may look strange; this is because they are an expression; one line of code that should return a value, which explains the lack of EOL (;) and the multiple use of returning a boolean value. (exotic things such as executing the backtick operator, PHP tags, echo, die, list, etc.) are not specifically specified)
javascript syntax php parsing
Christian
source share