3

你好吗。希望好...

我面临以下代码的问题。该strtr功能不起作用。它不输出任何东西...

if ($translate == "DrChatrikWeb") {
$convertarray = array(
"~" => "~",
"!" => "!",
"@" => "@",
"#" => "#",
"$" => "$",
"%" => "%",
"^" => "^",
"&" => "&",
"*" => "*",
"(" => "(",
")" => ")",
"_" => "_",
"+" => "+",
"`" => "`",
"1" => "1",
"2" => "2",
"3" => "3",
"4" => "4",
"5" => "5",
"6" => "6",
"7" => "7",
"8" => "8",
"9" => "9",
"0" => "0",
"-" => "_",
"=" => "=",
"Q" => "ਥ",
"W" => "ੱ",
"E" => "ਓ",
"R" => "੍ਰ",
"T" => "ਠ",
"Y" => "ੈ",
"U" => "ੂ",
"I" => "ੀ",
"O" => "ੌ",
"P" => "ਫ",
"{" => "{",
"}" => "}",
"|" => "।",
"q" => "ਤ",
"w" => "ੱ",
"e" => "ੲ",
"r" => "ਰ",
"t" => "ਟ",
"y" => "ੇ",
"u" => "ੁ",
"i" => "ਿ",
"o" => "ੋ",
"p" => "ਪ",
"[" => ".",
"]" => "॥",
"\\" => "\\",
"A" => "ੳ",
"S" => "ੰ",
"D" => "ਧ",
"F" => "ਾਂ",
"G" => "ਘ",
"H" => "੍ਹ",
"J" => "ਝ",
"K" => "ਖ",
"L" => "਼",
":" => ":",
"\"" => "\"",
"a" => "ਅ",
"s" => "ਸ",
"d" => "ਦ",
"f" => "ਾ",
"g" => "ਗ",
"h" => "ਹ",
"j" => "ਜ",
"k" => "ਕ",
"l" => "ਲ",
";" => ";",
"'" => "'",
"Z" => "ਢ",
"X" => "ਯ",
"C" => "ਛ",
"V" => "ੜ",
"B" => "ਭ",
"N" => "ਂ",
"M" => "ੰ",
"" => ",",
">" => ">",
"?" => "?",
"z" => "ਡ",
"x" => "ਣ",
"c" => "ਚ",
"v" => "ਵ",
"b" => "ਬ",
"n" => "ਨ",
"m" => "ਮ",
"" => ",",
"." => "।",
"/" => "/",
"¡" => "ੴ",
"«" => "॥",
"¬" => "#",
"R" => "੍ਰ",
"•" => "•",
"»" => "।",
"Ã" => "ੴ",
"Å" => "ੴ",
"Ç" => "☬",
"È" => "ਸ਼",
"É" => "ਖ਼",
"Ê" => "ਗ਼",
"Ë" => "ਜ਼",
"Ì" => "ਫ਼",
"Î" => "੍ਯ",
"Ñ" => "#",
"Ò" => "॥",
"Ü" => "ਲ਼",
"ñ" => "੧",
"ò" => "੨",
"ó" => "੩",
"ô" => "੪",
"õ" => "੫",
"ö" => "੬",
"÷" => "੭",
"ø" => "੮",
"ù" => "੯",
"ú" => "੦",
"ƒ" => "ਨੂੰ",
"“" => "“",
"”" => "”",
"Í" => "੍ਵ",
);
$string = strtr($texttoreplace, $convertarray);
echo $string;
}

该数组在旁遮普语中,即是一种印度语言......

这段代码运行良好......

$repp = array(
        "<br />" => " <br> ",
        " ," => " <punc>,</punc> ",
        " ." => " <punc>.</punc> ",
        " /" => " <punc>/</punc> ",
        " \\" => " <punc>\\</punc> ",
        " !" => " <punc>!</punc> ",
        " ?" => " <punc>?</punc> ",
        " :" => " <punc>:</punc> ",
        " ;" => " <punc>;</punc> ",
        " \"" => " <punc>\"</punc> ",
        " '" => " <punc>'</punc> ",
        " (" => " <punc>(</punc> ",
        " )" => " <punc>)</punc> ",
        " {" => " <punc>{</punc> ",
        " }" => " <punc>}</punc> ",
        " <" => " <punc><</punc> ",
        " >" => " <punc>></punc> ",
        " [" => " <punc>[</punc> ",
        " ]" => " <punc>]</punc> ",
        " &" => " <punc>&</punc> ",
        " $" => " <punc>$</punc> ",
        " @" => " <punc>@</punc> ",
        " #" => " <punc>#</punc> ",
        " %" => " <punc>%</punc> ",
        " ^" => " <punc>^</punc> ",
        " *" => " <punc>*</punc> ",
        " _" => " <punc>_</punc> ",
        " =" => " <punc>=</punc> ",
        " +" => " <punc>+</punc> ",
        " |" => " <punc>|</punc> ",
        " -" => " <punc>-</punc> ",
        "," => "<> <punc>,</punc> ",
        "." => "<> <punc>.</punc> ",
        "/" => "<> <punc>/</punc> ",
        "\\" => "<> <punc>\\</punc> ",
        "!" => "<> <punc>!</punc> ",
        "?" => "<> <punc>?</punc> ",
        ":" => "<> <punc>:</punc> ",
        ";" => "<> <punc>;</punc> ",
        "\"" => "<> <punc>\"</punc> ",
        "'" => "<> <punc>'</punc> ",
        "(" => "<> <punc>(</punc> ",
        ")" => "<> <punc>)</punc> ",
        "{" => "<> <punc>{</punc> ",
        "}" => "<> <punc>}</punc> ",
        "<" => "<> <punc><</punc> ",
        ">" => "<> <punc>></punc> ",
        "[" => "<> <punc>[</punc> ",
        "]" => "<> <punc>]</punc> ",
        "&" => "<> <punc>&</punc> ",
        "$" => "<> <punc>$</punc> ",
        "@" => "<> <punc>@</punc> ",
        "#" => "<> <punc>#</punc> ",
        "%" => "<> <punc>%</punc> ",
        "^" => "<> <punc>^</punc> ",
        "*" => "<> <punc>*</punc> ",
        "_" => "<> <punc>_</punc> ",
        "=" => "<> <punc>=</punc> ",
        "+" => "<> <punc>+</punc> ",
        "|" => "<> <punc>|</punc> ",
        "-" => "<> <punc>-</punc> "
    );
    $repps = strtr($texttoreplace, $repp);
    echo $repps;

请帮忙..

4

3 回答 3

5

是这对导致问题,删除它并且它可以工作

"" => ",",

正如手册所说:

如果 replace_pairs 包含一个空字符串 ("") 的键,则将返回 FALSE。

于 2012-07-14T06:29:00.800 回答
0

尝试这个:

$old_ch = array_keys($convertarray); 
$new_ch = array_values($convertarray); 
$string = str_replace($old_ch,$new_ch,$texttoreplace);
于 2012-07-14T06:21:12.727 回答
0

来自strstr函数手册页。

用法

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

如果needle不是字符串,则将其转换为整数并用作字符的序数值。

读到这里,由于 your$convertarray不是字符串,因此尝试将其转换为整数值(失败,strstr不执行)。

于 2012-07-14T06:17:27.717 回答