PHP Search and Replace question
Posted: Fri Apr 09, 2010 2:51 pm
Hi Everyone,
I'm currently using the "str_ireplace" function to replace some words in a text with something else. So far everything works fine. The problem I have is that within this text are html links and the replace function also replaces the words within the links. I do not want this.
Basically I would like to replace words within the text except for when this text lies between the < and > characters. I thought of using preg but I'm not sure how it would work with this also.
For example, in a sentence such as:
"The lamb lies <a href="?page=down">down</a> on broadway". I would like the word "down" shown as the link to be able to change to something else but not the "down" within the href itself.
Any geniuses out there to help me out?
Thanks,
Erick P.
I'm currently using the "str_ireplace" function to replace some words in a text with something else. So far everything works fine. The problem I have is that within this text are html links and the replace function also replaces the words within the links. I do not want this.
Basically I would like to replace words within the text except for when this text lies between the < and > characters. I thought of using preg but I'm not sure how it would work with this also.
For example, in a sentence such as:
"The lamb lies <a href="?page=down">down</a> on broadway". I would like the word "down" shown as the link to be able to change to something else but not the "down" within the href itself.
Any geniuses out there to help me out?
Thanks,
Erick P.