gpt4 book ai didi

php - iconv - 在输入字符串中检测到非法字符

转载 作者:IT王子 更新时间:2023-10-29 01:15:40 24 4
gpt4 key购买 nike

我没有发现任何违法行为 - 对可能存在的问题有何建议?

    if (strtolower($matches[1]) != 'utf-8') {
var_dump($matches[1]);
$xml = iconv($matches[1], 'utf-8', $xml);
$xml = str_replace('encoding="'.$matches[1].'"', 'encoding="utf-8"', $xml);
}

下面是我的调试/错误

string(12) "windows-1252"
Notice (8): iconv() [http://php.net/function.iconv]: Detected an illegal character in input string [APP/models/sob_form.php, line 16]

我已经验证了上面的代码确实是第16行

最佳答案

但是,如果您使用了已接受的答案,如果输入字符串中的字符无法音译,您仍会收到 PHP 通知:

<?php
$cp1252 = '';

for ($i = 128; $i < 256; $i++) {
$cp1252 .= chr($i);
}

echo iconv("cp1252", "utf-8//TRANSLIT", $cp1252);

PHP Notice: iconv(): Detected an illegal character in input string in CP1252.php on line 8

Notice: iconv(): Detected an illegal character in input string in CP1252.php on line 8

所以你应该使用 IGNORE,它将忽略不能音译的内容:

echo iconv("cp1252", "utf-8//IGNORE", $cp1252);

关于php - iconv - 在输入字符串中检测到非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8727735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com