preg_replace() that will not replace text inside HTML tags

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • countocram
    New Member
    • Sep 2006
    • 3

    preg_replace() that will not replace text inside HTML tags

    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!
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    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
    Code:
    cleanEntry = striptags(trim($_POST['seachterm']))

    Comment

    Working...