如何将PHP页面中的变量值传给HTML页面 我有两个文件,一共是PHP文件,一共是静态的HTML文件,如何将PHP中的变量值传到HTML文件中?如PHP中有一个变量A=12345678,我要把A的值12345678传到html文件中并在html文件中显示出来!不是参数传递哦!!!就是像写文件一样!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 重新写入去了,最简单的,把第二个HTML文件的代码放入到第一个PHP文件的代码,然后用file_put_contents写入到第二个文件了(这里在PHP代码就肯定可以根据变量的值进行写入)。第二种方法,你可以好像模板一样写入。 1、把HTML当做文件来读写,在指定位置插入你的变量值。2、使用模板。 可以自己写个小的模板类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都不错! php读取或修改配置型文件中指定关键字的值 utf-8 转 gb2312 在“猫扑”上是乱码,其它网站可以。求救! phpmyadmin打开之后是乱码??? mysql_ pconnect和mysql_connect 有什么区别呢 谁帮我优化这个函数 我查进程的时候,发现php.exe 的进程有好几个,是什么原因? 图形处理,找了一个GD library 的东西,但没配好。 如何判断用户连续三次的操作? PHP到底有没有显示客户端IP的函数。 如何让不同页面使用不同的SESSION值 火车票的骗局 Discuz 论坛的MySQL查询速度慢的问题
2、使用模板。
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都不错!