Lets Appear on the blog Vijay
January 11, 2007PHP Use of regular expression ereg_replace smartly
January 11, 2007I was working on the application and came accross a situation where I need to replace all character except the numeric ones. My text pattern was something similar to varchar(20). I initial thought to use substr, later moved to explode using “(” token. I suddenly strike is ereg_replace can help me to do this. After writing one line of code I am happy it solve the purpose.
echo ereg_replace(“[a-zA-Z()]“,”",”varchar(20)”);
[a-zA-Z()] searches for all the occurences in the string and replace them with supplied character.
I very hardly uses ereg_replace but from now onwards I will encourage myself and others to use ereg_replace.
Something you can always do at database level
January 9, 2007I found many developers even sometimes I do some code which could be possible at the database level. Why to format date at coding level when DATE_FORMAT function is available.
Developer should be careful enough to identify the cases where they can performes operation at database level. This will help to improve the overall performance and efficiency of your application.
I will be keep adding the tips about the same in this entry
First
=====
If you want to format date by fetching it from database, you can use DATE_FORMAT function.
eg. SELECT DATE_FORMAT(now(), ‘%y’) FROM tableName

Posted by Vijay Khambalkar
Posted by Vijay Khambalkar
Posted by Vijay Khambalkar 