By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

preg_replace() that will not replace text inside HTML tags

P: 3
I have big problem, I'm using preg_replace() function for my highlighter function, after searching for particular keyword, once the hightler check box is checked it will highlight the content that matches the search keyword, the problem is, it also highlight the text inside the HTML tags that matches the keywords.

here's the screenshot:



I need a preg_replace() function that will not replace the text inside HTML tags, particularly <img /> tag

you help will be appreciated, thanks!
Mar 27 '07 #1
Share this Question
Share on Google+
1 Reply


code green
Expert 100+
P: 1,726
If the user types a search term into the search box and you extract that from the $_POST array into a variable there should be no HTML tags. Also as all user entry is safer if you clean it first you should not be having this problem
Expand|Select|Wrap|Line Numbers
  1. cleanEntry = striptags(trim($_POST['seachterm'])) 
Mar 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.