Forum Moderators: coopster

Message Too Old, No Replies

limit preg_replace()

Can the number of replacements be limited?

         

ironik

2:46 am on Mar 8, 2005 (gmt 0)

10+ Year Member



I'm wanting to use a regex to replace keywords in some text with hyperlinks. I've got the regex's down pat, but is there some way to limit the number of replacements?

What I'm attempting to do is terminology highlighting + linking for key acroymns and words, but only want the first mention of the word to be highlighted, not the rest.

There's probably a flag, but I've been searching around and haven't come up with anything yet... :(

hiker_jjw

3:46 am on Mar 8, 2005 (gmt 0)



Check the preg_replace documentation (or whatever function you are trying to use) at php.net. I use it off and on when I can't remember the function options.

Sometime I use a Google Search such as

php.net preg_replace

Good Luck...

ironik

3:56 am on Mar 8, 2005 (gmt 0)

10+ Year Member



the php manual is always my first resort... but I somehow missed the [int limit] option, or didn't read it properly. Looks like you can limit it by a number as the last parameter in the preg_replace() function.

Thanks :)