note 24246 added to function.strtr

From: Date: Sat, 10 Aug 2002 14:18:20 +0000
Subject: note 24246 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-34679@lists.php.net to get a copy of this message
#!/bin/sh # This shell script generates a strtr() call # to translate from a character set to another. # Requires: gnu recode, perl, php commandline binary # # Usage: # Set set1 and set2 to whatever you prefer # (multibyte character sets are not supported) # and run the script. The script outputs # a strtr() php code for you to use. # # Example is set to generate a # cp437..latin9 conversion code. # set1=cp437 set2=iso-8859-15 result="`echo '<? for($c=32;$c<256;$c++)'\ 'echo chr($c);'\ |php -q|recode -f $set1..$set2`" echo "// This php function call converts \$string in $set1 to $set2"; cat <<EOF | php -q <?php \$set1='`echo -n "$result"\ |perl -pe "s/([\\\\\'])/\\\\\\\\\\$1/g"`'; \$set2='`echo -n "$result"|recode -f $set2..$set1\ |perl -pe "s/([\\\\\'])/\\\\\\\\\\$1/g"`'; \$erase=array(); \$l=strlen(\$set1); for(\$c=0;\$c<\$l;++\$c) if(\$set1[\$c]==\$set2[\$c])\$erase[\$set1[\$c]]=''; if(count(\$erase)) { \$set1=strtr(\$set1,\$erase); \$set2=strtr(\$set2,\$erase); } if(!strlen(\$set1))echo 'IRREVERSIBLE';else echo "strtr(\\\$string,\n '", ereg_replace('([\\\\\\'])', '\\\\\\1', \$set2), "',\n '", ereg_replace('([\\\\\\'])', '\\\\\\1', \$set1), "');"; EOF -- http://www.php.net/manual/en/function.strtr.php http://master.php.net/manage/user-notes.php?action=edit+24246 http://master.php.net/manage/user-notes.php?action=delete+24246 http://master.php.net/manage/user-notes.php?action=reject+24246

« previous php.notes (#34679) next »