str_replace与收到的字符串不起作用

时间:2015-08-19 21:47:50

标签: php facebook str-replace

我有一个功能:

public function _convert_strings($string)
{
    //$name = strtolower($string);

    $data = array(
        'ą'  => 'a',
        'Ą'  => 'a',
        'č'  => 'c',
        'Č'  => 'c',
        'ę'  => 'e',
        'Ę'  => 'e',
        'ė'  => 'e',
        'Ė'  => 'e',
        'į'  => 'i',
        'Į'  => 'i',
        'š'  => 's',
        'Š'  => 's',
        'ų'  => 'u',
        'Ų'  => 'u',
        'Ū'  => 'u',
        'ū'  => 'u',
        'ž'  => 'z',
        'Ž'  => 'z',
        '.'  => '-',
        ' '  => '-',
        '--' => '-',
        '!'  => '',
        '@'  => '',
        '#'  => '',
        '$'  => '',
        '%'  => '',
        '^'  => '',
        '&'  => '',
        '*'  => '',
        '('  => '',
        ')'  => '',
        '_'  => '',
        ','  => '',
        ';'  => '',
        ':'  => '',
        '|'  => '',
        '/'  => '',
        '{'  => '',
        '}'  => '',
        '+'  => '',
        '['  => '',
        ']'  => '',
        '"'  => '',
        '?'  => '',
        '>'  => '',
        '<'  => '',
        'Ä'  => 'a',
        'ä'  => 'a',
        'Ö'  => 'o',
        'ö'  => 'o',
        'ü'  => 'u',
        'Ü'  => 'u',
        'ß'  => 's',
        'Б'  => 'b',
        'Г'  => 'g',
        'Д'  => 'd',
        'Ж'  => 'z',
        'И'  => 'i',
        'Й'  => 'j',
        'Л'  => 'l',
        'Н'  => 'n',
        'П'  => 'p',
        'Р'  => 'r',
        'Ф'  => 'f',
        'Ц'  => 'ts',
        'Ч'  => '',
        'Ш'  => '',
        'Щ'  => '',
        'Ъ'  => '',
        'Ы'  => '',
        'Ь'  => '',
        'Э'  => 'e',
        'Ю'  => 'ju',
        'Я'  => 'ja',
        "'"  => ''
    );

    return str_replace(array_keys($data), array_values($data), $string);
}

而我正在尝试转换字符串“ArnasPečelis”但不是Arnas-Pecelis而是返回Arnas-Pea�elis ...

我应该提一下,字符串是来自Facebook登录后的数据。如果我用简单的单词改变字符串 - 它可以工作。

print_r($this->base->_convert_strings($data['user_profile']['name'])); // ouput -> Arnas-Pea�elis
print_r($this->base->_convert_strings('Arnas Pečelis')); // ouput ->  Arnas-Pecelis

那么问题出在哪里?我也在使用2.4 facebook API版本

0 个答案:

没有答案