phpnovice
phpnovice

Reputation: 25

Read then find and replace contents of HTML file using PHP?

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

Answers (1)

Surace
Surace

Reputation: 711

you can simply use

$output = str_replace($patterns, $replacements, $email);

Upvotes: 2

Related Questions