然后阅读然后使用PHP查找并替换HTML文件的内容?

时间:2012-09-17 16:37:20

标签: php html

我正在尝试创建一个电子邮件模板,并使用preg_replace替换文档中的单词。我对php很新,所以我不太清楚它的后勤。这就是我目前所拥有的 - 我希望它读取HTML / CSS文件然后替换我有占位符的单词。

<?php
$email =  file("email.html");
$patterns = array();
$patterns[0] = '/header/';
$patterns[1] = '/name/';
$patterns[2] = '/body/';
$replacements = array();
$replacements[0] = 'imageurl';
$replacements[1] = 'John Johnson';
$replacements[2] = 'Content';
$output = preg_replace($patterns, $replacements, $email);
echo $output;
?>

另外,我可以使用此代码替换图像吗?

1 个答案:

答案 0 :(得分:2)

你可以简单地使用

$output = str_replace($patterns, $replacements, $email);
相关问题