Re: CREATING A FILE with a TEMPLATE
| From: | Jonathan Sharp | Date: | Thu, 17 Oct 2002 15:47:14 +0000 |
| Subject: | Re: CREATING A FILE with a TEMPLATE | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120346@lists.php.net to get a copy of this message | ||
Try this instead:
$template = implode('', file('template.txt'));
$_POST['test'] = 'First variable';
$_POST['fname'] = 'John';
$_POST['lname'] = 'Doe';
/* COPY HERE */
function replaceVar($matched)
{
return $_POST[$matched[2]];} $output = preg_replace_callback('/(##([a-z0-9]*)##)/iUm', 'replaceVar', $template); /* TO HERE */ echo $output; template.txt is: Welcome ##fname## ##lname##, ##test## -js Marco Tabini wrote:
Try using explode: $data = explode ('##', $template); $result = ''; for ($i = 0; $i < count ($data); $i++) $s .= ($i % 2) ? $($data[$i]) : $data[$i]; I'm not sure that this works 100% because I'm doing it from memory, but hopefully it should put you on the right track. On Thu, 2002-10-17 at 10:35, Kevin Fradkin wrote:Hi, i would like to know if someone can help me.... my little problem is : i have a template and i want that every form filled on my website replace on my template ( where i put ##var01## ##var02## etc) and with that create a new file with the results... i just need how to read from that template all the code, copy it to the new file and replace the ##vars## with the $vars of the form If there is a kind soul who can help me... Thankyou! VM!.. Spooky -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php