visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: mysql function to remove html code ?


By: Nono Great Britain  Date: 11/06/2007 16:34:08  English  Points: 20 Status: Answered
Quality : Excellent
is there a mysql function to remove html code ?
By: VGR Date: 11/06/2007 17:18:10 English  Type : Answer
good point ;-)

In PHP, of course you know, you've the strip_tags() function. You can feed it with a list of allowed (inocuous) tags like I, B and U so that SCRIPT, IFRAME and other "funny" stuff is stripped away. This won't solve the javascript issue on some tage, BTW. Be careful with it. Don't rely only on strip_tags() to "sanitize" user-input data.

Also, ALWAYS addslash() data before writing to the DB, and as a last word, be warned against "magic quoting", it can lead to nasty surprises ;-)

Now, back to your question. If you want to stay at the mysql level to strip tags from data, I see no obvious solution execpt using a carefully crafted and unmaintainable regexp using

REGEXP

(or RLIKE, see this mysql manual page )

you could also, a bit similarly to strip_tags() in PHP, apply repeated and nested STR_REPLACE() calls so that unallowed tags are removed, leaving only the allowed (or forgotten ;-) ones in place.

My best idea is to try a bit with mysql with the manual on LIKE, RLIKE, STR_REPLACE() under your eyes, then if not satisfied, to turn to PHP for doing the job with strip_tags().

best regards

Do register to be able to answer

EContact
browser fav
page generated in 229.867940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page