A trick I've used many-a-time is based for example on the data posted 
from a form.

foreach ($_POST as $var=>$val)
    $data['%'.$var.'%'] = $val;
echo 
str_replace(array_keys($data),array_values($data),file_get_contents('mytemplate.txt'));

And mytemplate.txt has in it things like:

Dear %name%, thank you for your interest in %product% ....

str_replace takes arrays as input, as well as plain strings.

Cheers,

- Bob -

Stig Manning wrote:
> Hi James,
>
> James McGlinn wrote:
>   
>> That looks like str_replace() would do the trick rather than any  
>> regexp nastiness:
>>
>> $search = array(
>> '%name%',
>> '%address%'
>> );
>> $replace = array(
>> $name,
>> $address
>> );
>> $data = str_replace($search, $replace, $data)
>>   
>>     
>
> Interesting, I could extract the keys and values from my original 
> array(key=>value) (this is all I have to work with)  to make the $search 
> and $replace arrays.
>
> Thanks!
> Stig
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to