Jump to content


Strip HTML & Javascript

  • Please log in to reply
2 replies to this topic

#1 xyn

  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 06 October 2006 - 11:48 AM

Hey Guys,
Is there anyway of using PHP to check a "field" before it is
entered into a database, then removing all HTML and Javascript
from that message?

I was thinking of using str_replace.. but for that i would need to
mannually add all the HTML codes i want to remove and loop all
the fields through arrays etc..

Any ideas?

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 11:58 AM

A Regular Expression is what you're after... Do a search in the Regular Expression forum on this board as I'm sure there's loads of instances of this very request.

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2006 - 12:16 PM

just use strip_tags()
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users