RE: [PHP] Multiple replacements (WML/PHP)

From: Date: Wed, 18 Oct 2000 04:37:36 +0000
Subject: RE: [PHP] Multiple replacements (WML/PHP)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20785@lists.php.net to get a copy of this message
Hi Johan, > I need a little bit of help on multiple replacements. I'm > developing a WAP-site which will use the Swedish language (with > ÅÄÖ), and I have noticed that most WML interpretors doesn't like > any kind of characters outside the a-z/A-Z scope. > > I know that the &#<ASCII-num>; works for replacement (and that > the normal HTML-way, e.g. &auml;, doesn't work). > > So, any suggestions on how I replace all characters in a string > which are not in the normal (a-z/A-Z) scope to the &#XXX; form > (e.g. 'å' -> &#228;)? I think this is exactly what you need. <? function wmlentities($str) { $chars = preg_split("//",$str); while(list($k,$v) = each($chars)) { switch (ord($v)) { case 34: // encode '"' $chars[$k] = "&#034;"; break; case 38: // encode '&' $chars[$k] = "&#038;"; break; case 60: // encode '<' $chars[$k] = "&#060;"; break; case 62: // encode '>' $chars[$k] = "&#062;"; break; default: // encode all other special characters if (ord($v) > 127) $chars[$k] = "&#".ord($v).";"; } } return(implode("",$chars)); } $test = "\"<&ÅÄöüaui>"; print wmlentities($test); ?> Cheers, Matthias

« previous php.general (#20785) next »