Search code examples
phpusability

Automatically add "$" character into PHP scripts


I have a programming text editor (written in PHP) and want to remove the $ signs available in PHP scripts upon loading of the document for editing ... to "quietly" insert them back once the user saves the file. Basically, I want to save the user the work of always typing the $ icon in front of variables (similar to how you don't have to in, say, Python).

My question: With which PHP code could I insert the $ signs back into the script?

Even if the functionality would make some compromises and assumptions in terms of coding style -- i.e. not work in edge cases -- I think it would be very useful.

Edit: As I originally mentioned, I'm OK with compromises in terms of style. Here's an example syntax that might be easin' the parsin' and still be nicer to write IMO:

for (var i = 1; i <= 10; i++) { /* look ma, no $s! */ }

Solution

  • This is a crazy idea but this can be done. If you will have to tell the editor that these are the variables. To do this you will have to use var i,variable_name to let the editor know that these are variables. Or something in comments.