| 
	
 | 
 Posted by John Holmes on 01/05/05 23:54 
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
 
  
Navigation:
[Reply to this message] 
 |