note 109487 modified in function.str-replace by danbrown

From: Date: Mon, 30 Jul 2012 16:10:07 +0000
Subject: note 109487 modified in function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189513@lists.php.net to get a copy of this message
&#60;?php&#13;&#10;&#13;&#10;/**&#13;&#10; * Convert foreign 8859-1 characters into HTML entities.&#13;&#10; * &#13;&#10; * @param string $str&#13;&#10; * The string being parsed.&#13;&#10; * &#13;&#10; * @return string&#13;&#10; * The converted string.&#13;&#10; */&#13;&#10;public static function convert_chars_to_entities( $str )&#13;&#10;{&#13;&#10;&#9;$str = str_replace( &#39;À&#39;, &#39;&#38;#192;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Á&#39;, &#39;&#38;#193;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Â&#39;, &#39;&#38;#194;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ã&#39;, &#39;&#38;#195;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ä&#39;, &#39;&#38;#196;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Å&#39;, &#39;&#38;#197;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Æ&#39;, &#39;&#38;#198;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ç&#39;, &#39;&#38;#199;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;È&#39;, &#39;&#38;#200;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;É&#39;, &#39;&#38;#201;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ê&#39;, &#39;&#38;#202;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ë&#39;, &#39;&#38;#203;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ì&#39;, &#39;&#38;#204;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Í&#39;, &#39;&#38;#205;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Î&#39;, &#39;&#38;#206;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ï&#39;, &#39;&#38;#207;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ð&#39;, &#39;&#38;#208;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ñ&#39;, &#39;&#38;#209;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ò&#39;, &#39;&#38;#210;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ó&#39;, &#39;&#38;#211;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ô&#39;, &#39;&#38;#212;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Õ&#39;, &#39;&#38;#213;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ö&#39;, &#39;&#38;#214;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;×&#39;, &#39;&#38;#215;&#39;, $str ); // Yeah, I know. But otherwise the gap is confusing. --Kris&#13;&#10;&#9;$str = str_replace( &#39;Ø&#39;, &#39;&#38;#216;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ù&#39;, &#39;&#38;#217;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ú&#39;, &#39;&#38;#218;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Û&#39;, &#39;&#38;#219;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ü&#39;, &#39;&#38;#220;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Ý&#39;, &#39;&#38;#221;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;Þ&#39;, &#39;&#38;#222;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ß&#39;, &#39;&#38;#223;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;à&#39;, &#39;&#38;#224;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;á&#39;, &#39;&#38;#225;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;â&#39;, &#39;&#38;#226;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ã&#39;, &#39;&#38;#227;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ä&#39;, &#39;&#38;#228;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;å&#39;, &#39;&#38;#229;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;æ&#39;, &#39;&#38;#230;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ç&#39;, &#39;&#38;#231;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;è&#39;, &#39;&#38;#232;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;é&#39;, &#39;&#38;#233;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ê&#39;, &#39;&#38;#234;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ë&#39;, &#39;&#38;#235;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ì&#39;, &#39;&#38;#236;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;í&#39;, &#39;&#38;#237;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;î&#39;, &#39;&#38;#238;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ï&#39;, &#39;&#38;#239;& #39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ð&#39;, &#39;&#38;#240;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ñ&#39;, &#39;&#38;#241;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ò&#39;, &#39;&#38;#242;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ó&#39;, &#39;&#38;#243;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ô&#39;, &#39;&#38;#244;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;õ&#39;, &#39;&#38;#245;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ö&#39;, &#39;&#38;#246;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;÷&#39;, &#39;&#38;#247;&#39;, $str ); // Yeah, I know. But otherwise the gap is confusing. --Kris&#13;&#10;&#9;$str = str_replace( &#39;ø&#39;, &#39;&#38;#248;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ù&#39;, &#39;&#38;#249;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ú&#39;, &#39;&#38;#250;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;û&#39;, &#39;&#38;#251;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ü&#39;, &#39;&#38;#252;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ý&#39;, &#39;&#38;#253;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;þ&#39;, &#39;&#38;#254;&#39;, $str );&#13;&#10;&#9;$str = str_replace( &#39;ÿ&#39;, &#39;&#38;#255;&#39;, $str );&#13;&#10;&#9;&#13;&#10;&#9;return $str;&#13;&#10;}&#13;&#10;?&#62; --was-- <?php /** * Convert foreign 8859-1 characters into HTML entities. * * @param string $str * The string being parsed. * * @return string * The converted string. */ public static function convert_chars_to_entities( $str ) { $str = str_replace( 'À', '&amp;#192;', $str ); $str = str_replace( 'Á', '&amp;#193;', $str ); $str = str_replace( 'Â', '&amp;#194;', $str ); $str = str_replace( 'Ã', '&amp;#195;', $str ); $str = str_replace( 'Ä', '&amp;#196;', $str ); $str = str_replace( 'Å', '&amp;#197;', $str ); $str = str_replace( 'Æ', '&amp;#198;', $str ); $str = str_replace( 'Ç', '&amp;#199;', $str ); $str = str_replace( 'È', '&amp;#200;', $str ); $str = str_replace( 'É', '&amp;#201;', $str ); $str = str_replace( 'Ê', '&amp;#202;', $str ); $str = str_replace( 'Ë', '&amp;#203;', $str ); $str = str_replace( 'Ì', '&amp;#204;', $str ); $str = str_replace( 'Í', '&amp;#205;', $str ); $str = str_replace( 'Î', '&amp;#206;', $str ); $str = str_replace( 'Ï', '&amp;#207;', $str ); $str = str_replace( 'Ð', '&amp;#208;', $str ); $str = str_replace( 'Ñ', '&amp;#209;', $str ); $str = str_replace( 'Ò', '&amp;#210;', $str ); $str = str_replace( 'Ó', '&amp;#211;', $str ); $str = str_replace( 'Ô', '&amp;#212;', $str ); $str = str_replace( 'Õ', '&amp;#213;', $str ); $str = str_replace( 'Ö', '&amp;#214;', $str ); $str = str_replace( '×', '&amp;#215;', $str ); // Yeah, I know. But otherwise the gap is confusing. --Kris $str = str_replace( 'Ø', '&amp;#216;', $str ); $str = str_replace( 'Ù', '&amp;#217;', $str ); $str = str_replace( 'Ú', '&amp;#218;', $str ); $str = str_replace( 'Û', '&amp;#219;', $str ); $str = str_replace( 'Ü', '&amp;#220;', $str ); $str = str_replace( 'Ý', '&amp;#221;', $str ); $str = str_replace( 'Þ', '&amp;#222;', $str ); $str = str_replace( 'ß', '&amp;#223;', $str ); $str = str_replace( 'à', '&amp;#224;', $str ); $str = str_replace( 'á', '&amp;#225;', $str ); $str = str_replace( 'â', '&amp;#226;', $str ); $str = str_replace( 'ã', '&amp;#227;', $str ); $str = str_replace( 'ä', '&amp;#228;', $str ); $str = str_replace( 'å', '&amp;#229;', $str ); $str = str_replace( 'æ', '&amp;#230;', $str ); $str = str_replace( 'ç', '&amp;#231;', $str ); $str = str_replace( 'è', '&amp;#232;', $str ); $str = str_replace( 'é', '&amp;#233;', $str ); $str = str_replace( 'ê', '&amp;#234;', $str ); $str = str_replace( 'ë', '&amp;#235;', $str ); $str = str_replace( 'ì', '&amp;#236;', $str ); $str = str_replace( 'í', '&amp;#237;', $str ); $str = str_replace( 'î', '&amp;#238;', $str ); $str = str_replace( 'ï', '&amp;#239;', $str ); $str = str_replace( 'ð', '&amp;#240;', $str ); $str = str_replace( 'ñ', '&amp;#241;', $str ); $str = str_replace( 'ò', '&amp;#242;', $str ); $str = str_replace( 'ó', '&amp;#243;', $str ); $str = str_replace( 'ô', '&amp;#244;', $str ); $str = str_replace( 'õ', '&amp;#245;', $str ); $str = str_replace( 'ö', '&amp;#246;', $str ); $str = str_replace( '÷', '&amp;#247;', $str ); // Yeah, I know. But otherwise the gap is confusing. --Kris $str = str_replace( 'ø', '&amp;#248;', $str ); $str = str_replace( 'ù', '&amp;#249;', $str ); $str = str_replace( 'ú', '&amp;#250;', $str ); $str = str_replace( 'û', '&amp;#251;', $str ); $str = str_replace( 'ü', '&amp;#252;', $str ); $str = str_replace( 'ý', '&amp;#253;', $str ); $str = str_replace( 'þ', '&amp;#254;', $str ); $str = str_replace( 'ÿ', '&amp;#255;', $str ); return $str; } http://php.net/manual/en/function.str-replace.php

« previous php.notes (#189513) next »