开发者

What is this character ( Â ) and how do I remove it with PHP?

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 el开发者_高级运维se 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?


"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.


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


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)


I use this one a lot

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


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, 'Â', ' ');


Use Bellow codes

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


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")


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


To remove â character from string

mysqli_set_charset($con,"utf8");

$price = "₹ 250.00";

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

Result : 250.00

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜