发新话题
打印

[求助] 一个难以理解的现象

一个难以理解的现象

a.php的代码片段:
复制PHP内容到剪贴板
PHP代码:
<title><?php echo $title.'-某某网站口号!'?> </title>

b.php的代码片段:
复制PHP内容到剪贴板
PHP代码:
<title><?php echo $title?> -某某网站口号!</title>
这两段代码有什么区别呢,会导致下面这个奇怪的现象:
1. a.php在FireFox和IE7上都显示正常
2. b.php则是:
在firefox上包含该代码的页面显示正常
在IE7上包含该代码的页面显示空白页面,但查看页面源代码,却是正常的,也就是说,仅仅是IE7没有把给页面渲染出来而已
这里给出我的问题演示代码:
IE7NoDisplayIssue.zip (883 Bytes)

想来想去不得其解,不知道大家有没有遇到过类似问题呢?

[ 本帖最后由 rongjunxue 于 2008-2-23 12:12 编辑 ]
做书虫也做玩家!
http://rongjunxue.viminta.com

TOP

注意网页编码放在 title前面

通常出现这样是你的网页编码是utf-8
而中文出现在编码前导致浏览器不能识别编码

[ 本帖最后由 psdshow 于 2008-2-23 12:03 编辑 ]
复制内容到剪贴板
代码:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head profile="http://www.w3.org/2000/08/w3c-synd/#"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="HTML Tidy for Mac OS X (vers 1st March 2004), see www.w3.org" />

<meta name="keywords" content="W3C, World Wide Web, Web, WWW, Consortium, computer, access, accessibility, semantic, worldwide, W3, HTML, XML, standard, language, technology, link, CSS, RDF, XSL, Berners-Lee, Berners, Lee, style sheet, cascading, schema, XHTML, mobile, SVG, PNG, PICS, DOM, SMIL, MathML, markup, Amaya, Jigsaw, free, open source, software" />
<meta name="description" content="The World Wide Web Consortium (W3C) is an international consortium where Member organizations, a full-time staff, and the public work together to develop Web standards. W3C primarily pursues its mission through the creation of Web standards and guidelines designed to ensure long-term growth for the Web. Over 400 organizations are Members of the Consortium. W3C is jointly run by the MIT Computer Science and Artificial Intelligence Laboratory (MIT CSAIL) in the USA, the European Research Consortium for Informatics and Mathematics (ERCIM) headquartered in France, Keio University in Japan, and has additional Offices worldwide." />

<title>World Wide Web Consortium</title>
<link id="meta" rel="rel:meta" href="http://www.w3.org/2000/08/w3c-synd/#meta" />
<link rel="meta" href="/Overview-about.rdf" />
<link rel="stylesheet" type="text/css" href="/StyleSheets/home.css" />
<link rel="bookmark" href="#technologies" title="Technologies |" />
<link rel="bookmark" href="#news" title="News |" />
<link rel="bookmark" href="#search" title="Search |" />
<link rel="contents" href="#contents" title="Contents |" />
<link rel="bookmark" href="#Offices" title="Offices |" />
<link rel="bookmark" href="#systems" title="Systems |" />
<link rel="bookmark" href="#donors" title="Supporters |" />
<link rel="bookmark" href="#footnotes" title="Footnotes |" />
<link rel="alternate" type="application/rss+xml" title="W3C Home Page News RSS Channel" href="http://www.w3.org/2000/08/w3c-synd/home.rss" />

<style type="text/css">
/**/
   div.spot-image img {
      margin-bottom: 20px;
   }
/**/
</style>
</head>
看一下W3C是怎么做HEAD的

TOP

引用:
原帖由 psdshow 于 2008-2-23 12:02 发表
注意网页编码放在 title前面
确实是,把页面编码放到前面就不存在显示不了的问题了。
但如果页面编码放在title后面,为什么a.php就可以正常显示,b.php才出问题呢,这点我还是搞不明白

[ 本帖最后由 rongjunxue 于 2008-2-23 12:21 编辑 ]
做书虫也做玩家!
http://rongjunxue.viminta.com

TOP

引用:
原帖由 rongjunxue 于 2008-2-23 12:20 发表

确实是,把页面编码放到前面就不存在显示不了的问题了。
但如果页面编码放在title后面,为什么a.php就可以正常显示,b.php才出问题呢,这点我还是搞不明白
浏览器的解析情况不同吧,呵呵
因为在a.php的时候,是由php来打印的,你的字符串编码为gb2312,而在b.php,你交给了html,html打印字符串时候的编码按照charset的设置

TOP

因为php会先解释程序,也就是将所有的php代码都解释完了再输出,而html不用解释直接就输出了。
因此html的输出必须在编码设置之后,而php代码输出部分则不需要。
不知道这样理解正确不?
One Bird In PhpChina

TOP

PHP会考虑不少东西的
发新话题