myljb
新手上路

UID 70258
精华
0
积分 29
帖子 15
金钱 29 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-3-24 来自 广东
状态 离线
|
[广告]: Enom域名自助付费 自助注册 自助PUSH 主流域名COM等一律57.99元年
求救 关于替换字符串的问题
<?php
$file = file_get_contents('htmview/index.html');
$arr['title'] ="标题";
$arr['main'] = "内容";
foreach ($arr as $key=>$val){
}
echo str_replace('{'.$key.'}',$val,$file);
?>
输出结果:
<html>
<head>
<title>标题</title>
</head>
<body>
{main} //这里不能替换
</body>
------------------
//再改为这样子:
------------------
<?php
$file = file_get_contents('htmview/index.html');
$arr['title'] ="标题";
$arr['main'] = "内容";
foreach ($arr as $key=>$val){
}
echo str_replace('{'.$key.'}',$val,$file);
?>
输出结果:
<html>
<head>
<title>{title}</title> //这里不能替换...
</head>
<body>
内容
</body>
</html>
<?php
$file = file_get_contents('htmview/index.html');
$arr['title'] ="标题";
$arr['main'] = "内容";
foreach ($arr as $key=>$val){
}
echo '{'.$key'}'.$val
?>
输出是: {title}标题{main}内容
|
|