You are here: Re: [PHP] Really simple regex « PHP « IT news, forums, messages
Re: [PHP] Really simple regex

Posted by John Nichel on 06/08/05 22:17

Dotan Cohen wrote:
> Now, I know that this is easy, but I am embarassed to say that I can't
> find a regex tutorial that will show me how to match any occurances of
> x and replace them with one x:
>
> xxxxx >x
> xx > x
> x > x
>
> $string="I have xxxxxxxx apples!";
> $string=preg_replace("-regex here-","x", $string);
> print "$string";
>
> I have x apples!

preg_replace ( "/x+/", "x", $string );
preg_replace ( "/x{1,}/", "x", $string );

But those will also change a letter 'x' in a word, so you'll probably
need to tinker with that part too.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@kegworks.com

 

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

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