Reputation: 25
I'm trying to create an email template and replace words in the document using preg_replace. I'm pretty new to php so I'm not too clear about the logistics of it. This is what I currently have-- I want it to read the HTML/CSS file then replace words where I have placeholders.
<?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;
?>
Also, is it possible for me to replace with an image using this code?
Upvotes: 2
Views: 2878
Reputation: 711
you can simply use
$output = str_replace($patterns, $replacements, $email);
Upvotes: 2