PDA

View Full Version : protect a link from str_ireplace


cosy
09-26-2008, 01:53 PM
$this->post['message'] = str_ireplace('hello', '<a href="www . hello . com">hello </a> ', $this->post['message']);
this code is to add a link for certain words in postbit a link the problem is if a link is posted and contain the word "hello" the link get broken
any way to put a "protection" on links ?

Lynne
09-26-2008, 02:38 PM
Hi cosy.

The way I work with this is it only does a string replace for words my Mods write and the phrases they use would not be something they would use in the normal course of posting. For example, we have a Band Restriction Policy on our site in the faq. When a Mod refers a user to that page in the faq, all they have to write is the title and my rewrite will make it a link to the faq - Band Restriction Policy (http://www.mysite.com/faq.php).

However! Something else you can do.... I use "str_ireplace" which replaces the string no matter if the characters are capitalized or not. You could change it to "str_replace" and it is more specific. You could make it so people have to post "HELLO" and it gets replaced and most likely that is going to not replace the url (unless it is written as www. HELLO.com).