views:

350

answers:

2

New to Eclipse IDE and was wondering is there is a way of adding an auto complete/change so that if I type:

mres

it will translate it to

mysql_real_escape_string()

I know of the normal PHP code completion, but couldn't see anything about making custom shortcuts.

Thanks, Niggles

A: 

Well, I don't know about the IDE but why not type mres and when you're done with the code, you can replace all occurrances with "mysql_real_escape_string".

Another way is to create a function like this:

 function mres($string)
 {
 return mysql_real_escape_string($string);
 }
netrox
The danger in that is code that may be confusing if someone else took it over - if it's a real PHP function I prefer to leave it as is.
niggles
yup, useless encapsulation that serve no specific purpose.
Donny Kurnia
+1  A: 

If you using PDT, create your own PHP Template. From the menu Window > Preferences, choose PHP > Editor > Templates. Click New button, then use mres as the template name, then put

mysql_real_escape_string(${cursor})

as a pattern.

To use it, just type mres and press Ctrl+Space. If there are no other alternative for the mres, then your template will be used right away. If you happened to have 2 or more templates that started with mres or contain mres in the template name, a popup will be showed so you can choose which you want to use.

Donny Kurnia
Works a treat. Thanks heaps.
niggles