大家好,请问你们有过这种经历么.用一个PHP文件file_get_contents()一个模板文件,echo出来后发现位置不是原来的居中了,成了靠左了.是怎么回事?我初步判断了一下,是PHP文件头有几行include_once()代码惹的祸.把include_once屏蔽掉就好了.是怎么一回事呢? 

解决方案 »

  1.   

    上代码。
    你的include_once()怎么写的?
      

  2.   

    那只能说明你所include的文件中有css样式,才会令你的页面布局改变
      

  3.   

    引入后 的模版文件 是在php的一个变量里, 也许找不到css了
      

  4.   


    news.php文件<?php
    include_once 'inc/cla.connect_db.php';
    //没有include_once时在IE6中是正常的.有的时候只有在IE6的时候不正常
    $html=file_get_contents('tpl/news.tpl');$newscates='1';
    $curpostion='2';
    $mainContent='3';
    $html=str_replace('{$newscates}',$newscates, $html);
    $html=str_replace('{$curposition}',$curpostion, $html);
    $html=str_replace('{$mainContent}',$mainContent, $html);echo $html;
    ?>
    include_once里的文件 就是一个连接数据库的类,自己写的.<?php
    class connect_db{
    private $host;
    private $name;
    private $pass;
    private $db;private $query;
    private $result; function __construct($host,$name,$pass,$db){
    $this->host=$host;
    $this->name=$name;
    $this->pass=$pass;
    $this->db=$db;
    $this->connect();
    }
    function connect(){
    mysql_connect($this->host,$this->name,$this->pass) or die(mysql_error());
    mysql_select_db($this->db) or die ("没有该数据库:$this->db");
    mysql_query("SET NAMES 'utf8'");
    }}
    $connect_db=new connect_db("localhost","root","","dbdalianwa");
    ?>news.tpl文件
    http://download.csdn.net/detail/dalianwa/4337836
      

  5.   

    给出可供测试的 url机器不会出错,出错的只是人
      

  6.   

    客户端的问题,你只要比较客户端的html源码及css/js等