Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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/4/string/5.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/4/string/5.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_Character Encoding - Fatal编程技术网

这个字符(Â;)是什么?如何使用PHP删除它?

这个字符(Â;)是什么?如何使用PHP删除它?,php,string,character-encoding,Php,String,Character Encoding,这是一个大写字母a,上面有^: 它显示在从网页中提取的字符串中。它显示了原始站点上原始字符串中以前存在空白的位置。这是存储在我的数据库中的实际字符。当我回显包含它的字符串时,它也会显示在我的网站上 当我最初处理网页时,我意识到这是一个字符编码问题,但我现在被数据库中的这些字符所困扰。我必须在显示这个字符时转换它,或者在输出包含它的html之前在php中的其他地方转换它。我不能重新处理原始文件 我试过str_replace()和html_entity_decode(),但都没有做任何事情 我还应该

这是一个大写字母a,上面有^:


它显示在从网页中提取的字符串中。它显示了原始站点上原始字符串中以前存在空白的位置。这是存储在我的数据库中的实际字符。当我回显包含它的字符串时,它也会显示在我的网站上

当我最初处理网页时,我意识到这是一个字符编码问题,但我现在被数据库中的这些字符所困扰。我必须在显示这个字符时转换它,或者在输出包含它的html之前在php中的其他地方转换它。我不能重新处理原始文件

我试过str_replace()和html_entity_decode(),但都没有做任何事情


我还应该尝试什么?

它实际上不是一个字符,很可能是由于内容编码和浏览器编码不一致造成的。尝试将输出页面的编码设置为您正在使用的编码

e、 g.在本节中,输出:

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
echo”“;
(将UTF-8调整到您正在使用的任何值)

“拉丁语1”是您的问题所在。一个网页大约有65256个UTF-8字符,不能存储在拉丁语-1代码页中

对于你眼前的问题,你应该能够

$clean = str_replace(chr(194)," ",$dirty)
不过,我会尽快将您的数据库切换为使用utf-8,因为问题几乎肯定会再次发生。

使用以下代码

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
echo htmlspecialchars_decode($your_string, ENT_QUOTES);
echo”“;
echo htmlspecialchars_decode($your_string,ENT_QUOTES);
我经常用这个

function cleanStr($value){
    $value = str_replace('Â', '', $value);
    $value = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
    return $value;
}

在web中使用不同的字符集时会出现此问题

要解决此问题(在示例中使用utf-8):

在页面的
中添加
字符集

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form name="..." method=".." id=".."  accept-charset="utf-8">
如果您使用php+MySQLi来处理表单,那么应该确保数据库连接也支持您的字符集。程序风格:

mysqli_set_charset($link, "utf8");
和面向对象的风格:

$mysqli->set_charset("utf8")
这对我很有用:

$string = "Sentence ‘not-critical’ and \n sorting ‘not-critical’ or this \r and some ‘not-critical’ more. ' ! -.";
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $string);

实际上,我必须拥有所有这些:

    <--!DOCTYPE html--> 
    <--html lang="en-US"-->
    <--head-->
    <--meta charset="utf-8"-->   
    <--meta http-equiv="X-UA-Compatible" content="IE=edge"--> 
    <--meta name="viewport" content="width=device-width, initial-scale=1"--> 
    <--meta http-equiv="Content-Type" content="text/html; charset=utf-8/" /--> 

从字符串中删除–字符

mysqli_set_charset($con,“utf8”)

$price=“250.00”

$price2=preg_replace('/[^(\x20-\x7F)]*/',''$price)


结果:250.00

这是来自数据库的,因此最好的选择是使用SQL查询从数据库中删除,如:

更新产品集描述=替换(描述,';

您不应该通过str\u replace删除它们,您应该首先修复编码问题。看看这个:这个+1-这是一个需要修复根本原因的问题(尽管仅仅更改标题可能不会完全消除它,具体取决于情况),这是存储在我的数据库中的实际字符。这会改变现状吗?我的数据库编码是拉丁文1(默认)。我不太熟悉编码问题。哦,是的,对不起,我没有仔细阅读问题。在这种情况下,从另一个站点提取数据后,需要检测其编码,并在存储它们之前将其转换为数据库的编码。通常,它是通过解析我给出的标题来完成的,但是根据你抓取的站点的不同,它可能会变得复杂。这听起来是解决问题的正确方法。当我回到项目的那一部分时,我会做出改变。在输出字符之前,有没有关于使用PHP的临时解决方案的建议,或者这是不可能的?Unicode代码空间上升到U+10FFFF,因此大约有一百万个代码点,给出或获取一些非法字符。下面是一个有用的图表,可以引用如下字符:@Ignacio——非常正确——我将自己限制在UTF-16字符集上。:-}UTF-16具有相同的字符数。您可能指的是UCS-2。感谢您的这个技巧,以防有人会搜索解决方案,如何从SQL Server到wordpress提取拉丁语-1文本,这里是str_replace(chr(194),“”,mb_convert_编码($val,'UTF-8','ISO-8859-1');现在,我的文本中缺少了一些空格,但编码字符已经不存在了。这是唯一一个为我去掉字符的答案。这使得到lb