Hi I am looking to replace words in an html email I am loading via file_get_contents
Here is my code:
<?
$message = file_get_contents("http://www.MYwebsiteExample.com/EmailConfirmation.php");
$message = preg_replace('/SAD/', "HAPPY", $message);
// Also tried this below and it does not work either
$message = str_replace('/SAD/', "HAPPY", $message);
?>
I am hoping to find all the patters of SAD (case sensitive) and replace them with HAPPY. For some reason if I use file_get_contents it doesn't seem to be working.
Thanks
UPDATE: Jan 22, 2013
Actually, sorry Correction when I add the $ it does not work. Its not necessary for my code. I can do a work around but this does not work below:
$message = str_replace("$SAD", "HAPPY", $message); /// does not work. Not sure why
$message = str_replace("SAD", "HAPPY", $message); /// without the $ it does work.
var_dump($message);output? You might not even be getting any results. allow_url_fopen might be set to off.<span class="firstletter">S</span>AD. If this is the case, you would need a different regexp, or better still, use DOM manipulation.<?php, not<?. Just to pick up a good habit ;-)