Reply to Re: eregi_replace and Regular Expression Quandry

Your name:

Reply:


Posted by Andy Hassall on 11/07/69 11:25

On Mon, 29 Aug 2005 20:55:46 GMT, "saiena" <saiena@nospam_thetellingtree.com>
wrote:

>Is there a way in my regular expression syntax to cause alternating
>occurences of the search string to be replaced?
>
>Here's my code:
>
>$item[content] = eregi_replace($search_string, $replace_string,
>$item[content]);
>
>This successfully replaces all occurences of $search_string.
>
>Any way to reaplce every other?

The solutions I can think of all need non-greedy expressions, at which point
you need to use the PCRE (preg_*) functions - which IMHO is worth switching to
anyway unless you're really tied to the more basic ereg syntax.

At which point you can either use a clever expression, or just do it with
preg_replace_callback and a Boolean flag or counter accessed by the callback to
work out whether it's an odd or even call, and so whether to replace or not.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original 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

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