On 8 Feb 2005 09:40:27 -0800, petrovitch <we*******@deltafarms.com> wrote:
How do I change only the first occurence of a token in a string?
How do I change only the nth occurence of a token in a string?
How do I change the first alpha character after the nth occurence of a
token in a string?
The answer to these questions will allow me to display raw text as
beautiful magazine style layouts using style sheets without manually
altering each document.
Change first occurance:
preg_replace("/test/","cake",$text,1);
Use the limit parameter to do just one replace.
Change the 3rd occurance + next character. It isn't nice, but works.
preg_replace("/((?:.*?test.*?){2})test(\s*)(\w)(.*)/s","\\1cake\\2<span>\\3</span>\\4",$text);
Passes two occurances, to replace the third.
Puts span tags around the next alpha char.
Hope this helps.
--
Stian