本文介绍了PHP包括和口音(他们显示为 )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用PHP include来包含一个PHP文件,其中有HTML。一些内容有法国口音,这些在网站上显示为。。
这里是我包含的PHP文件:
$ b$ b
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html dir =ltrxmlns =http://www.w3.org/1999/xhtml>
< head>
< meta content =en-ushttp-equiv =Content-Language/>
< title> Accueil< / title>
< meta content =text / html; charset = utf-8http-equiv =Content-Type/>
< meta content =ChangementcréativitérêvebutsêtrecentréPlénitudepersonnelDéveloppementtransformation修改翻译修改新的视觉审查énergie正面满意度接受赦免name =keywords/>
< link href =masterstyles.css =stylesheettype =text / css/>
< link href =menustyles.css =stylesheettype =text / css/>
< link href =menudropdown.css =stylesheettype =text / css/>
< td class =tbsyles>& nbsp;
< h3 class =bigorange> ACTIVITÉSÀVENIR ...< / h3>
< p class =horizblue> < / p>
< p class =bigblack> < br />
Inscrivez-vousànosconférenceset formations
< br />
< br />
< / p>
< h4 class =orange>可能在这里的一些文字示例< br />
< / h4>
< p class =horizblue> & nbsp;< / p>
< h3 class =bigorange> < br />
ABONNEZ-VOUS ...< / h3>
< p class =nopadding> Ànotre liste d'envoi< / p>
< form method =postaction =<?php echo $ PHP_SELF;?>>
<?PHP
function process_info(){
if(isset($ _ POST ['email']))
{
$ b b $ email = $ _ POST [email];
$ email = strtolower($ email);
$ action =subc;
//检查电子邮件是否存在
//检查电子邮件是否正确(基本检查)
$ 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或$ test2< 2或$ test3< 7或$ test4!= 1)
{
print< h6> Il a une erreur avecvôtreemail< / h6>;
print< h6> Aucune informations ontétéenvoyer< / h6>;
}
else
{
print< h5>vôtreaddress est enregistrer,Merci< / h5>;
//如果他们想要订阅,请执行...
$ file =emaillist-666XXX.txt;
//尝试获取文件的内容
if(file_exists($ file)){
//如果文件已经在服务器中,其内容为粘贴到变量$ file_content
$ file_content = file_get_contents($ file);
}
else {
//如果文件不存在,尝试创建它
//如果文件无法创建(可能是由于目录权限的问题),
//通知用户(第一个用户将是网站管理员,谁必须解决问题)。
$ cf = fopen($ file,w)或die();
fclose($ cf);
}
//如果请求已从邮件列表中注册,请添加电子邮件至文件
if($ action ==subc){
/ /检查电子邮件是否已经注册
if(strpos($ file_content,< $ email>)> 0){die();}
//将电子邮件列表(将其附加到文件)
$ cf = fopen($ file,a);
fputs($ cf,\\\
$ email); //新电子邮件在新行中写入文件
fclose($ cf);
}
}
}
}
process_info();
?>
& nbsp;< p class =nopadding> Votre Courriel< / p>
< input name =emailtype =textclass =style3/>
< input name =Submittype =submitvalue =OK/>< / form>
< p class =horizblue>< / p>
< h3 class =bigorange> < br />
OUTILS GRATUIT ...< / h3>
< p class =nopadding> Amusez-vous avec des outilsintéressants< / p>
< / td>如果浏览器认为您使用的是另一个编码,那么就会发生这种情况:
解决方案
尝试在打印html之前,在您的php文件中添加以下内容:
header('Content-type:text / html; charset = utf-8');
//或
header('Content-type:text / html; charset = iso8859-15');
并添加
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
<! - or - >
< meta http-equiv =Content-Typecontent =text / html; charset = ISO8859-15/> < head>< / head> 之间的
$ c>标签
UPDATE :刚刚看到您的更新文件。您需要添加 header('Content-type:text / html; charset = utf-8');
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" >
<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"> </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();
?>
<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>
解决方案 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');
这篇关于PHP包括和口音(他们显示为 )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!