phpencodingiso

Encoding issue ISO-charset vs utf-8


When I input data such as : Œ, œ, Ÿ, … , €, ≤, ≥, ∞, ≈, ≠, – , — , ‐ , ‑ , ‹ ›, “ ”, ‘ ’ And then try to access data from the $_REQUEST['some_value'] I get this as my output

¼, ½, ¾,  … , ¤,  ≤, ≥, ∞, ≈, ≠, – , — , ‐ , ‑ , ‹ ›,  “ ”, ‘ ’

What exactly is happening here?


Solution

  • We call this Character encoding.

    When you input special characters, PHP converts them to their HTML entity representations. This happens when PHP processes form submissions or access request data.

    To handle this, you can use this on page

    header('Content-Type: text/html; charset=utf-8');
    

    if AJAX,

    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
    

    Where to place PHP header


    FYI: To check data use echo htmlspecialchars($value); But when processing $originalValue = $_REQUEST['some_value']; is enough.