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

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

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

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

You are looking at a capital A followed by a superscript caret: Â. In your database, this isn't just a typo; it is a specific byte sequence resulting from a classic encoding mismatch. You likely pulled HTML content where the original site used Windows-1252 (often colloquially called "Western European") encoding, but your application expected UTF-8.

In Windows-1252, the byte 0xC2 represents Â. In UTF-8, that same two-byte sequence (0xC2 0xA0) is required to represent a non-breaking space. If you took bytes meant for an accented character or a specific symbol and interpreted them as UTF-8 without converting the source first, you end up with this visible artifact. str_replace() fails because it treats  as three distinct characters: A, ^, and nothing (or sometimes interpreted as two if the font renders the combining diacritic). html_entity_decode() also fails here because the browser or PHP parser has already rendered the entity, or worse, you are trying to decode an HTML entity inside a string that is actually just raw bytes representing a non-breaking space.

The core issue is that this character often represents a non-breaking space. If the source site used UTF-8 but saved the file as ISO-8859-1, the browser would interpret 0xC2 0xA0 as Â. When you scrape that page, you get that string in your database. To fix it, you must normalize the encoding before storage or sanitize it upon retrieval.

If you cannot reprocess the original documents, you have to handle this at the PHP layer. The most robust approach is to explicitly convert the string's internal encoding using mb_convert_encoding. This function tells PHP exactly how to interpret the bytes currently in memory and what format they should be transformed into.

Here is a practical implementation pattern for cleaning incoming strings:

function cleanNonBreakingSpace($string) {
    // Attempt to decode from Windows-1252 to UTF-8
    $converted = mb_convert_encoding(
        $string, 
        'UTF-8', 
        'Windows-1252'
    );

    // Replace the resulting non-breaking space (or the literal  artifact) with a standard space
    return str_replace(['Â ', 'Â', ' ', ' '], ' ', $converted);
}

This function assumes your database is stored in UTF-8, which is best practice. By forcing the conversion to Windows-1252 first (even if the data looks like garbage), mb_convert_encoding can often resolve the byte mapping correctly because it knows that 0xC2 0xA0 in a Western European context usually maps to a specific non-breaking space concept.

However, relying solely on encoding conversion can be brittle if the source is inconsistent. A more aggressive strategy involves using regular expressions to strip the literal character regardless of its semantic meaning. If you are certain the character is an artifact and not valid content, preg_replace offers a direct solution:

$cleanString = preg_replace('/[\xC2\xA0]/', ' ', $string); // Matches raw bytes if needed via mb_regex_encoding
// Or simpler if dealing with the visible chars in a UTF-8 context:
$cleanString = str_replace(['Â', ' ', ' '], ' ', $string);

It is important to note that str_replace operates on characters, not bytes. If your database column is defined as utf8mb4, the string  is technically three UTF-8 code points (A, combining circumflex accent, space) or two if interpreted differently depending on the font rendering engine. But in 99% of scraping cases, it is a non-breaking space masquerading as a character.

If you are building an application with Laravel, ensure your config/app.php sets the default encoding to UTF-8 and that your database connection uses the utf8mb4 collation. This prevents PHP from silently re-interpreting bytes when echoing strings to the view layer. If you are using a custom repository or raw queries, always cast the result to UTF-8 immediately after fetching.

One final pitfall: blindly stripping spaces can break text formatting. If your scraper relies on multiple spaces for indentation in code blocks or pre-formatted text, replacing all instances of  with a single space might collapse that layout. In such cases, consider preserving the whitespace structure by matching the specific byte sequence rather than the rendered character name.

For complex scraping workflows where encoding is unknown, the safest bet is to treat the input as binary, detect the BOM or charset signature, and normalize to UTF-8 before storing anything in the database.

Our network