You are here: Re: replace all occurrences of a substring in a string (RE) « All PHP « IT news, forums, messages
Re: replace all occurrences of a substring in a string (RE)

Posted by MaKroZ on 02/14/06 19:59

On Mon, 13 Feb 2006 19:09:33 +0100, Piratron wrote:

> well, I'm afraid you didn't understand me. Simple str_replace function
> wont solve my problem because I have to replace text between two html tags!
> I can determine the position of first an last tag with a loop or
> something and then replace the text inside it. But I have a dozens of
> those tags so I really need a smart function to find all that
> occurrences. What will be the faster method? The one I just mentioned or
> using eregi_replace or preg_replace?

Oh, so '{POST_CODE}' is not the pattern? OK, sorry I didn't understand you
right. Seeking for positions of tags in a loop is a good approach too. I
don't know which of approaches will work faster, but it can be determined
by an experiment though. If you want to try re, here is an example for
your problem:

ereg_replace("(<!--ec1-->).*(<!--ec2-->)","\\1$repl\\2", $string);

"This function scans string for matches to pattern, then replaces the
matched text with replacement. The modified string is returned."

eregi_replace is the same but it's case insensitive.



--
nn My bookmarks:
(oo) http://www.yakutia.org
| | http://www.theisplist.com
|/\| http://www.tenpieces.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

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