Re: CREATING A FILE with a TEMPLATE

From: Date: Thu, 17 Oct 2002 16:08:41 +0000
Subject: Re: CREATING A FILE with a TEMPLATE
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-120352@lists.php.net to get a copy of this message
It probably is slower, but I would wager a guess that the amount of time is insignificant and not notice able. If you do benchmark it, you only must compare the 'COPY HERE' through 'TO HERE' since that is what is doing the replacement. I'll test it also later today. -js Marco Tabini wrote:
Uhm... wouldn't this be actually slower? You're reading the file, exploding into an array (file), then re-imploding it into a single variable, and then using regular expressions with a callback, so that a function has be called every time a match is found. It'd be interesting to find out which method is faster. I'll try timing both and I'll let you all know. Cheers, Marco On Thu, 2002-10-17 at 11:47, Jonathan Sharp wrote:
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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#120352) next »