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

发布于 2024-12-01 16:50:01 字数 327 浏览 0 评论 0原文

它是一个大写字母 A,顶部有一个 ^: Â

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

当我最初处理网页时,我意识到这是一个字符编码问题,但现在我在数据库中遇到了这些字符。我必须在显示该字符时转换该字符,或者在输出包含该字符的 html 之前在 php 中的其他位置进行转换。我无法重新处理原始文件。

我尝试过 str_replace() 和 html_entity_decode() 但都没有执行任何操作。

我还应该尝试什么?

It's a capital A with a ^ on top: Â

It is showing up in strings pulled from webpages. It shows up where there was previously an empty space in the original string on the original site. This is the actual character that is stored in my database. It's also what displays on my website when I echo a string that contains it.

I realize it's a character encoding problem when I originally process the webpage, but I am now stuck with these characters in my database. I have to convert this character when it is displayed, or somewhere else in the php before outputting html that contains it. I cannot reprocess the original documents.

I have tried str_replace() and html_entity_decode() and neither do anything.

What else should I try?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

夜吻♂芭芘 2024-12-08 16:50:01

“Latin 1”是你的问题。网页可用的大约 65256 个 UTF-8 字符无法存储在 Latin-1 代码页中。

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

$clean = str_replace(chr(194)," ",$dirty)

但是我会尽快将您的数据库切换为使用 utf-8,因为问题几乎肯定会再次发生。

"Latin 1" is your problem here. There are approx 65256 UTF-8 characters available to a web page which you cannot store in a Latin-1 code page.

For your immediate problem you should be able to

$clean = str_replace(chr(194)," ",$dirty)

However I would switch your database to use utf-8 ASAP as the problem will almost certainly reoccur.

回忆躺在深渊里 2024-12-08 16:50:01

这对我有用:

$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);

This works for me:

$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);
葬シ愛 2024-12-08 16:50:01

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

例如,在该部分中,输出:(

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";

将 UTF-8 调整为您使用的任何内容)

It isn't really one character, and is likely caused by misalignment between content encoding and browser's encoding. Try to set the encoding of your outputted page to what you are using.

e.g. In the section, output:

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";

(Adjust UTF-8 to whatever you are using)

东走西顾 2024-12-08 16:50:01

我经常用这个

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

I use this one a lot

function cleanStr($value){
    $value = str_replace('Â', '', $value);
    $value = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
    return $value;
}
分分钟 2024-12-08 16:50:01

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

UPDATE products SET description = REPLACE(description, 'Â', ' ');

This is coming from database so the best option will be remove from database using a SQL query like:

UPDATE products SET description = REPLACE(description, 'Â', ' ');
网白 2024-12-08 16:50:01

使用波纹管代码

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
echo htmlspecialchars_decode($your_string, ENT_QUOTES);

Use Bellow codes

echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
echo htmlspecialchars_decode($your_string, ENT_QUOTES);
盗琴音 2024-12-08 16:50:01

在您的网络中使用不同的字符集时会出现此问题。

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

在页面的 中添加 charset

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

在您提交的任何表单中添加 accept-字符集:

<form name="..." method=".." id=".."  accept-charset="utf-8">

如果您使用 php+MySQLi 来处理表单,您应该确保数据库连接也支持您的字符集。过程风格:

mysqli_set_charset($link, "utf8");

和面向对象风格:

$mysqli->set_charset("utf8")

This problem occurs when using different charset in your web.

To solve this (using utf-8 in the examples):

in the <HEAD> of your page add charset:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

In any form you submit add accept-charset:

<form name="..." method=".." id=".."  accept-charset="utf-8">

If you are using php+MySQLi to process your form, you should make sure the database connection is also supporting your charset. Procedural style:

mysqli_set_charset($link, "utf8");

and object oriented style:

$mysqli->set_charset("utf8")
内心旳酸楚 2024-12-08 16:50:01

我实际上必须拥有这一切:

    <--!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/" /--> 

I Actually had to have all of this:

    <--!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/" /--> 
诠释孤独 2024-12-08 16:50:01

从字符串中删除 â 字符

mysqli_set_charset($con,"utf8");

$price = "₹ 250.00";

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

结果:250.00

To remove â character from string

mysqli_set_charset($con,"utf8");

$price = "₹ 250.00";

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

Result : 250.00

缺⑴份安定 2024-12-08 16:50:01

我面临着同样的问题。当我使用 utf8_decode() 函数时它得到解决。

I was facing same problem. It get solved when I used utf8_decode() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文