coding special characters in html

From: Date: Sun, 17 Nov 2002 22:34:00 +0000
Subject: coding special characters in html
Groups: php.general 
Request: Send a blank email to php-general+get-124834@lists.php.net to get a copy of this message
Hi all, I'm cooking tothether a tiny php html editor right now, (textarea kind of thing). To treat the text properly I need to encode characters like '"', '<', '>', and friends into something that doesn't confuse the browser. I got it to work with regexps, you can see a part of the decoder below. But I believe there must be some automatic stuff in php which does this. Anybody out there knowing about such a function? $pattern = "/&#34;/"; $replacement = "\""; $string = preg_replace($pattern ,$replacement, $string); By the way, do you think encoding and decoding special characters like this may replace addslashes() and stripslashes()? The html pages will be stored in a MySQL database. Also, addslashes() will reduce the chance of bad stuff being passed to MySQL. But is there a function which stops client-side scripts in whatever is entered by the user? Regards, Børge

« previous php.general (#124834) next »