mysqli_sql_exception 错误:Incorrect string value ,php怎么去掉这些 �����mysql不支持的字如何把字符串 处理为 干净且只包含有效的UTF-8字符

zblog1年前zblog问题解答35
$fileContent = iconv("UTF-8", "UTF-8//IGNORE", $fileContent);
因此,iconv("UTF-8", "UTF-8//IGNORE", $fileContent);

这行代码的实际作用是尝试清理$fileContent字符串中
可能存在的任何无法正确以UTF-8编码表示的字符。

尽管在这个特定的例子中,由于输入和输出都是UTF-8,
理论上不应该有无法转换的字符,
但如果原始数据在某种方式下
被错误地标记或处理为UTF-8,
这行代码可以作为一种尝试,
以忽略并去除那些可能由于编码错误或损坏而导致的问题字符。

简而言之,这行代码的目的
是尝试确保$fileContent字符串
是干净且只包含有效的UTF-8字符,

尽管在这个特定的转换场景下(UTF-8到UTF-8),
其效果可能非常有限。
array ( 'code' => 1366, 
'message' => 'Incorrect string value: \'\\xBC\\xA4\\xBB\\xEE\\xC2\\xEB...\' 
for column \'log_Intro\' at row 1', 'file' => 'mysqli.php', 
'line' => 305, 'type' => 'mysqli_sql_exception', )  
php怎么去掉这些 �����mysql不支持的字符 
(写入mysql 会报错Debug_Exception_Handler(0 => mysqli_sql_exception: Incorrect string value:)


相关文章

php curl 典型案例代码 curl例子 curl_init() curl_setopt

      $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);...

ZBLOG 获取表字段名字

global $zbp;     $fieldID = $zbp->datainfo['Post'][&#...

宝塔续签证书 SSH证书 续签Let's Encrypt证书

宝塔续签证书 SSH证书 续签Let's Encrypt证书

续签Let's Encrypt证书 shell 脚本/www/server/panel/pyenv/bin/python3 -u /www/server/panel/class/acme_v2...

可以下 chrome 版本对应的所有驱动 chrome驱动 chromedriver.exe

https://googlechromelabs.github.io/chrome-for-testing/#stable 从这里下载最新的 浏览器测试驱动 https://googlechrome...

php 变量保存为字符串 序列化和反序列化

<?php // 定义一个数组变量 $array = array('apple', 'banana', &#...