Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP's strip_tags() equivalent MYSQL function

    Hello forums!
    I was just wondering to know how this can be accomplished:
    Case:
    Code:
    SELECT * FROM cms_pages WHERE body LIKE '%keywords%';
    Problem: Suppose my keyword=font & body field contains:
    [code=text]<div style="font-size:12px">This is a body area</div>[/code]
    then above query fetches this row.

    I would like to know,
    is there any function to strip the html tags while executing query?
    something like:
    Code:
    SELECT * FROM cms_pages WHERE strip_tags(body) LIKE '%keywords%';
    or by any other means?

    Thanks

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I don't think so. Why can't you just do this when you are getting the data from the db?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    MySQL does not natively support expression replacement. It can find matches, but not capture them for replacement.

    Just out of curiosity I did a google search for "mysql strip_tags" and "mysql regex replace", only to find that half the first page results are you having copied/pasted this question on at least 5 other forums.

    As already suggested here and in many of the replies in other locations, I'd agree it would be best to store the data twice, once as the original and once in another column (or table w/ a foreign key) with the tags stripped using PHP.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •