You are here: Re: [PHP] Regular expression question « PHP « IT news, forums, messages
Re: [PHP] Regular expression question

Posted by b-bonini on 08/11/05 16:21

n Thu, 11 Aug 2005, Leon Vismer wrote:

> Hi
>
> I would like to convert from one naming convention within a sql statement to
> another.
>
> I have the following,
>
> <code>
> $str = "insert into userComment (userID, userName, userSurname) values (0,
> 'Leon', 'Vismer')";
>
> $match = array(
> "/([a-z]+)(ID)/",
> "/([a-z]+)([A-Z])/"
> );
>
> $replace = array(
> "\$1_id",
> "\$1_\$2"
> );
>
> $nstr = preg_replace($match, $replace, $str);
> echo $nstr ."\n";
> </code>
>
>
> the above gets me to
> insert into user_Comment (user_id, user_Name, user_Surname) values (0, 'Leon',
> 'Vismer')
>
> however I want to get to
>
> insert into user_comment (user_id, user_name, user_surname) values (0, 'Leon',
> 'Vismer')
>
> Some help from the regex experts ;-)


Just a quick note; why dont' you search on "user" since it's the constant and replace 'user[A-Z]' with 'user_[a-z]' or in the case of userID 'user[A-Z]{2}'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация