mgr*_*aph 0 php string reverse
我有电子邮件:ue.aporue.lraporue@otlatnom-dratta.nhoj
我希望它像:
john.attard-montalto@europarl.europa.eu
当我使用revWords('ue.aporue.lraporue@otlatnom-dratta.nhoj');我得到:
eu.europa.europarl@montalto-attard.john
function revWords($string) {
//We need to find word boundries
$wordChars = 'abcdefghijklmnopqrstuvwxyz';
$buffer = '';
$return = '';
$len = strlen($string);
$i = 0;
while ($i < $len) {
$chr = $string[$i];
if (($chr & 0xC0) == 0xC0) {
//UTF8 Characer!
if (($chr & 0xF0) == 0xF0) {
//4 Byte Sequence
$chr .= substr($string, $i + 1, 3);
$i += 3;
} elseif (($chr & 0xE0) == 0xE0) {
//3 Byte Sequence
$chr .= substr($string, $i + 1, 2);
$i += 2;
} else {
//2 Byte Sequence
$i++;
$chr .= $string[$i];
}
}
if (stripos($wordChars, $chr) !== false) {
$buffer = $chr . $buffer;
} else {
$return .= $buffer . $chr;
$buffer = '';
}
$i++;
}
return $return . $buffer;
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我谢谢
PHP有一个内置函数来反转字符串:http: //php.net/manual/en/function.strrev.php
使用有什么不对
//strrev ( string $string )
echo strrev('ue.aporue.lraporue@otlatnom-dratta.nhoj');
//Returns john.attard-montalto@europarl.europa.eu
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
239 次 |
| 最近记录: |