Re: Re: XML Filters for illegal characters
| From: | John Holmes | Date: | Wed, 05 Jan 2005 21:54:18 +0000 |
| Subject: | Re: Re: XML Filters for illegal characters | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-205693@lists.php.net to get a copy of this message | ||
Jones, Douglas 1 wrote:
I think that a function just like htmlentities but one that just removes characters that are illegal but can not be fixed would be the ideal solution.How do you define what can and cannot be fixed, though? You'd have to know the "bad" characters and in that case, a simple str_replace() is all you need. $bad_characters = array('^','*','#'); $text = str_replace($bad_characters,'',$text); $text = htmlentities($text); Or, since you don't really know what's "bad" then you'd want to define what's good. You could use get_html_translation_table() to find everything that htmlentities() will convert and then combine those characters, alphanumeric characters and whitespace into a preg_replace to match anything that's *not* one of those characters and erase it. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com