Jump to content

str_replace array


andyd34

Recommended Posts

I am trying to replace some fields in a file using the following code

 

$test = array(
	'NAME'      =>	'A N Other', //$mailName,
	'MAIL'       =>	'[email protected]', //$mailEmail,
	'TELE'	=>	'01111111111', //$mailTel,
	'BODY'	=>	'This is a test message', //$mailBody,
	'TIME'	=>	date('g:ia'),
	'DATE'	=>	date('l jS F Y'),
);

$file = file_get_contents("./languages/en/messeges/new_message.txt");

$value = array();
foreach($test as $key => $val) {
$value[] = str_replace('{'.$key.'}', $val, $file);
}

$file ="<pre>$file</pre>";

echo implode($file, $value);

 

here is the contents of "./languages/en/messeges/new_message.txt"

 

 

New message received on {DATE} at {TIME}

 

From: {NAME}

 

Contact Number: {TELE}

 

Email: {MAIL}

 

----------------------------------------------------------------------------

 

{BODY}

 

----------------------------------------------------------------------------

 

 

Can someone please help as its echoing the complete file for every instance, 1 at a time

Link to comment
https://forums.phpfreaks.com/topic/229040-str_replace-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.