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?
Â, â (a-circumflex) is a letter of the Inari Sami, Skolt Sami, Romanian, and Vietnamese alphabets. This letter also appears in French, Friulian, Frisian, Portuguese, Turkish, Walloon, and Welsh languages as a variant of the letter "a".
In PHP to remove characters from beginning we can use ltrim but in that we have to define what we want to remove from a string i.e. removing characters are to be known. $str = "geeks" ; // Or we can write ltrim($str, $str[0]); $str = ltrim( $str , 'g' );
Using str_replace() Method: The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).
You can also remove a specified character or substring from a string by calling the String. Replace(String, String) method and specifying an empty string (String. Empty) as the replacement.
"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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With