note 79174 modified in function.htmlentities by danbrown

From: Date: Sun, 17 May 2009 16:52:19 +0000
Subject: note 79174 modified in function.htmlentities by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154903@lists.php.net to get a copy of this message
Yet another "help paste from MS Word" function. Characters from ISO-8859-1 charset are left in peace, while entities are built for non-standard characters from Windows CP1252. <?php function win1252toIso( $string ) { // These chars seem to be not contained // in php's CP1252 translation table static $extensions = array( 142 => "&Zcaron;", 158 => "&zcaron;" ); // Go through string and decide char by char: // "leave as is or build entity?" $newStr = ""; for( $i=0; $i < strlen( $string ); $i++ ) { $ord = ord( $string[$i] ); if ( in_array( $ord, array_keys( $extensions ) ) ) { // build entity using extra translation table $newStr .= $extensions[$ord]; } else { // build entity using php's translation table // or leave as is $newStr .= ( $ord > 127 && $ord < 160 ) ? htmlentities( $string[$i], ENT_NOQUOTES, "CP1252" ) : $string[$i]; } } return $newStr; } ?> --was-- Yet another "help paste from MS Word" function. Characters from ISO-8859-1 charset are left in peace, while entities are built for non-standard characters from Windows CP1252. function win1252toIso( $string ) { // These chars seem to be not contained // in php's CP1252 translation table static $extensions = array( 142 => "&Zcaron;", 158 => "&zcaron;" ); // Go through string and decide char by char: // "leave as is or build entity?" $newStr = ""; for( $i=0; $i < strlen( $string ); $i++ ) { $ord = ord( $string[$i] ); if ( in_array( $ord, array_keys( $extensions ) ) ) { // build entity using extra translation table $newStr .= $extensions[$ord]; } else { // build entity using php's translation table // or leave as is $newStr .= ( $ord > 127 && $ord < 160 ) ? htmlentities( $string[$i], ENT_NOQUOTES, "CP1252" ) : $string[$i]; } } return $newStr; } http://php.net/manual/en/function.htmlentities.php

« previous php.notes (#154903) next »