日期:2014-05-17  浏览次数:20555 次

PHP代码优化问题
a.php
<?php
$title='3月5号开始会';
$classid='1';
$a='a';
$b='b';
$c='c';
$d='d';
?>

b.php
<?php
if (file_exists('a.php')) {
include('a.php');
$filesname= '文本文件.txt';
$txt = file($filesname);
foreach($txt as $row) {
  $text = $text.$row.'<br />';}
$footer=file_get_contents('footer.html');

switch ( $classid )
{
case '1' :
$classname = '东区';
break;
case '2' :
$classname = '南区';
break;
case '3' :
$classname = '西区';
break;
case '4' :
$classname = '北区';
break;
default:
$classname = '其他';
};
}else {
Header( "HTTP/1.1 301 Moved Permanently" );  
Header( "Location: /error.html" );
};
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title><?php echo $title;?></title>
</head>
<body>
<div id="class">
<?php echo $classname;?>
</div>
<div id="text">
<?php echo array['text'];?>
</div>
<div id="footer">
<?php echo $footer;?>
</div>
</body>
</html>


怎么优化PHP代码让浏览速度更快呢?
a.php 用数据方式比较好吧?


------解决方案--------------------
就这几行代码,没有优化的必要

优化了你也感觉不到效果
------解决方案--------------------
写在一个文件中,不要来什么嵌套包含就是最优化的了。
------解决方案--------------------
这代码最需要优化的地方就是格式了,不注意缩进的代码最难看了