PHP: How print/echo accents/utf-8

10,250

Solution 1

I think this would work for you:

echo utf8_encode($var);

http://php.net/manual/en/function.utf8-encode.php

Solution 2

Make sure your files are UTF-8 encoded.

You may also add character encoding to form tag

<form action="demo_form.asp" accept-charset="UTF-8">

Share:
10,250
asdrubal
Author by

asdrubal

.Front-End{ Designer: Photoshop, 'Corel Draw', SVG; Web Designer: 'Sublime Text'; Developer: JQuery, JS, PHP, Wordpress, Python; }

Updated on June 27, 2022

Comments

  • asdrubal
    asdrubal almost 2 years

    I got the basic structure:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    

    and the input:

    <input type="text" name="var"/>
    

    to get with:

    $var = iconv('UTF-8', 'ASCII//TRANSLIT', $_POST['var']);
    //or
    $var = $_POST['var'];
    

    and show like:

    echo $var;
    //or
    print_r($var);
    //or
    print_r(iconv('UTF-8', 'ASCII//TRANSLIT', $var));
    

    i try force a new header:

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

    and with .htaccess:

    AddDefaultCharset UTF-8
    

    and nothing works :( The only things that appears is: jos? instead josé

    how solve it?

  • asdrubal
    asdrubal over 9 years
    This is a good answer, thanks
  • asdrubal
    asdrubal over 9 years
    I wish, but i still don't have enough reputation. One day! :)