Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php从右向左反转电子邮件_Php_String_Reverse - Fatal编程技术网

php从右向左反转电子邮件

php从右向左反转电子邮件,php,string,reverse,Php,String,Reverse,我有电子邮件:ue.aporue。lraporue@otlatnom-德拉塔·恩霍伊 我希望它像: 约翰·阿塔德-montalto@europarl.europa.eu 当我使用revue.aporue这个词时。lraporue@otlatnom-德拉塔·恩霍伊;我得到: 欧盟,欧罗巴。europarl@montalto-阿塔德·约翰 function revWords($string) { //We need to find word boundries $wordChars

我有电子邮件:ue.aporue。lraporue@otlatnom-德拉塔·恩霍伊

我希望它像:

约翰·阿塔德-montalto@europarl.europa.eu

当我使用revue.aporue这个词时。lraporue@otlatnom-德拉塔·恩霍伊;我得到:

欧盟,欧罗巴。europarl@montalto-阿塔德·约翰

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;
}
有人能帮我吗谢谢为什么不行


PHP有一个内置函数来反转字符串:

使用有什么问题

//strrev ( string $string )

echo strrev('ue.aporue.lraporue@otlatnom-dratta.nhoj');

//Returns john.attard-montalto@europarl.europa.eu

现在我明白了为什么求职面试中经常会出现反串任务
//strrev ( string $string )

echo strrev('ue.aporue.lraporue@otlatnom-dratta.nhoj');

//Returns john.attard-montalto@europarl.europa.eu