www.webdeveloper.com
Results 1 to 7 of 7

Thread: PHP's strip_tags() equivalent MYSQL function

  1. #1
    Join Date
    Feb 2007
    Posts
    84

    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. #2
    Join Date
    Jan 2010
    Location
    Kyiv, Ukraine
    Posts
    23
    Yes, you can, but you should use "REGEXP" instead of "LIKE"

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    AFAIK there's nothing built in. You could build a SQL function I'm sure, but personally I would just store 2 versions of the content, one with tags and one without. For me the greater disk usage would be preferable to running some complex function with every query.

  4. #4
    Join Date
    Jan 2010
    Location
    Kyiv, Ukraine
    Posts
    23
    Mindzai, why he can't simply use regexp in mysql query?

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    Regex is processor expensive. You wouldn't want to run the regex for each call to the database or you would quickly bring even a moderate server to its knees with a low-med volume site.

  6. #6
    Join Date
    Jan 2010
    Location
    Kyiv, Ukraine
    Posts
    23
    criterion9, yes, it's work not so fast, but author of the topic didn't ask about fast solution and why did you decide that he going to run this query very often. Maybe he going to run it under admin panel sometimes?

  7. #7
    Join Date
    Jan 2009
    Posts
    3,346
    SELECT * FROM cms_pages WHERE body LIKE '%keywords%';
    Appears to be a "site search" type feature. Thus I assume that it will be run regularly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles