PHP Include and accents (They show up as �)

2020-03-02 01:44发布

I'm using PHP include to include a PHP file that has HTML in it. some of the content has french accents and these show up as � on the site. How can this be solved?

Thanks

Here is the PHP file I include:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<title>Accueil</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Changement créativité rêve buts être centré Plénitude personnel                                                                  Développement transformation Modification nouveauté avancement bien-être                    Nouvelle vision ressentis L’énergie positive satisfaction l’acceptation Pardon" name="keywords" />
<link href="masterstyles.css" rel="stylesheet" type="text/css" />
<link href="menustyles.css" rel="stylesheet" type="text/css" />
<link href="menudropdown.css" rel="stylesheet" type="text/css" />

<td class="tbsyles" >&nbsp;
        <h3 class="bigorange"> ACTIVITÉS À VENIR…</h3>
        <p class="horizblue"> </p>
        <p class="bigblack"> <br />
        Inscrivez-vous à nos conférences et formations
        <br />
        <br />
        </p>
        <h4 class="orange"> Example of some text that could be here<br />
        </h4>
        <p class="horizblue"> &nbsp;</p>
        <h3 class="bigorange"> <br />
        ABONNEZ-VOUS… </h3>
        <p class="nopadding"> À notre liste d’envoi </p>

    <form method="post" action="<?php echo $PHP_SELF;?>">
<?PHP
function process_info(){

     if(isset($_POST['email']))
 {

 $email=$_POST["email"];
   $email=strtolower($email);
    $action = "subc";

       // check if email exists

        // check whether email is correct (basic checking)
           $test1=strpos($email, "@");                                     //value must be >1
           $test2=strpos(substr($email,strpos($email,"@")), ".");          //value must be >1
           $test3=strlen($email);                                          //value must be >6
           $test4=substr_count ($email,"@");                               //value must be 1

 if ($test1<2 or $test2<2 or $test3<7 or $test4!=1)
             {

             print "<h6>Il a une erreur avec vôtre email</h6>";
             print "<h6>Aucune informations ont été envoyer</h6>";


             }
             else
             {
             print "<h5>vôtre address est enregistrer, Merci </h5>";


              //If they wanted to subsribe, do it...


             $file = "emaillist-666XXX.txt";

             // lets try to get the content of the file
if (file_exists($file)){
        // If the file is already in the server, its content is pasted to variable $file_content
        $file_content=file_get_contents($file);
}
else{
        // If the file does not exists, lets try to create it
        //   In case file can not be created (probably due to problems with directory permissions),
        //   the users is informed (the first user will be the webmaster, who must solve the problem).
        $cf = fopen($file, "w") or die("");
        fclose($cf);
}

// IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE
if ($action=="subc"){
        // check whether the email is already registered
        if(strpos($file_content,"<$email>")>0){die("");}
        // write the email to the list (append it to the file)
        $cf = fopen($file, "a");
        fputs($cf, "\n$email");       // new email is written to the file in a new line
        fclose($cf);

}
}
}
}


process_info();


?>


            &nbsp;<p class="nopadding">Votre Courriel</p>
            <input name="email" type="text" class="style3" />
                    <input name="Submit" type="submit" value="OK" /></form>

                <p class="horizblue"></p>
                <h3 class="bigorange"> <br />
                OUTILS GRATUIT… </h3>
                <p class="nopadding">Amusez-vous avec des outils intéressants</p>   
        </td>

5条回答
爷的心禁止访问
2楼-- · 2020-03-02 02:11

What is the charset of the HTML page? It sounds like the charset of the PHP file and the HTML within it differ. You might want to check out:

For more help, please post some code, specifically the doctype which is being output and any calls to PHP charset functions.

查看更多
够拽才男人
3楼-- · 2020-03-02 02:12

That happens if the browser thinks your using another encoding than you actually use.

try to add the following in your php file before any html is printed:

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

and add

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- or -->
<meta http-equiv="Content-Type" content="text/html; charset=ISO8859-15" />

between the <head></head> tags

UPDATE: just saw your update with the file. you need to add header ('Content-type: text/html; charset=utf-8');

查看更多
做自己的国王
4楼-- · 2020-03-02 02:15

Try using

<meta http-equiv="Content-Language" content="fr"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
查看更多
淡お忘
5楼-- · 2020-03-02 02:18

If switching the charset doesn't fix it, you can use entities. &eacute; for é, &ocirc; for ô and so on

P.S. 'Il a une erreur avec vôtre email' -> You should say 'Il y a', it's votre not vôtre and email can be translated to 'courriel' :)

查看更多
别忘想泡老子
6楼-- · 2020-03-02 02:23

I had the same issue with a website for a French hotel.

Changing the charset to "ISO-8859-1" instead of "UTF-8" did the trick.

Example: < form method="post" name="contact" action="send_mail.php" accept-charset="ISO-8859-1" >

查看更多
登录 后发表回答