我有两个文件,一共是PHP文件,一共是静态的HTML文件,如何将PHP中的变量值传到HTML文件中?
如PHP中有一个变量A=12345678,我要把A的值12345678传到html文件中并在html文件中显示出来!不是参数传递哦!!!就是像写文件一样!!!

解决方案 »

  1.   

    重新写入去了,最简单的,把第二个HTML文件的代码放入到第一个PHP文件的代码,然后用file_put_contents写入到第二个文件了(这里在PHP代码就肯定可以根据变量的值进行写入)。第二种方法,你可以好像模板一样写入。
      

  2.   

    1、把HTML当做文件来读写,在指定位置插入你的变量值。
    2、使用模板。
      

  3.   

    可以自己写个小的模板类
    class templet{ 
         private $source_file; 
         function get_file($filename){ 
             $this->source_file = file_get_contents($filename); 
         } 
         function parse($tags,$vals){ 
             if(!is_array($tags)){ 
                return preg_replace("|{".$tags."}|",$vals,$this->source_file);  
             }else{ 
                $an = count($tags); 
                for($i=0;$i<$an;$i++){ 
                   $tags[$i] = "|{".$tags[$i]."}|"; 
                } 
               return preg_replace($tags,$vals,$this->source_file);  
            } 
         } 
      }  
    呵呵,当然smarty、phplib中的template.inc都不错!