Created
February 28, 2013 13:56
-
-
Save zxteloiv/5056902 to your computer and use it in GitHub Desktop.
reverse Chinese characters per line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/php/bin/php | |
<?php | |
function cstrrev($str) | |
{ | |
$len = strlen($str); | |
for($i = 0; $i < $len; $i++) | |
{ | |
$char = $str{0}; | |
if(ord($char) > 127) | |
{ | |
$i++; | |
if($i < $len) | |
{ | |
$arr[] = substr($str, 0, 2); | |
$str = substr($str, 2); | |
} | |
} | |
else | |
{ | |
$arr[] = $char; | |
$str = substr($str, 1); | |
} | |
} | |
return join(array_reverse($arr)); | |
} | |
$f = fopen("q.txt", "r"); | |
while(!feof($f)) { | |
$line = fgets($f); | |
echo cstrrev(trim($line))."\n"; | |
} | |
fclose($f); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
非常好,一直也想寫这种程序… ^o^