RE: [PHP] Replace or regex?
| From: | Dan Joseph | Date: | Thu, 30 Sep 2004 15:38:34 +0000 |
| Subject: | RE: [PHP] Replace or regex? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198288@lists.php.net to get a copy of this message | ||
Hi,
> > I have a string: ##CODE## and I want to replace that with <a
> > href="somewhere.php?id=CODE">CODE</a>
I handle %code% tags in some templates I use... here's the code I have..
function show ($template, $tag) {
$file = fopen ($template, "r") or
die($error_string());
while (!feof($file)) {
$line_in = fgets($file, 1024);
$line_out .= $line_in;
}
if ($tag != 0) {
foreach ($tag as $name => $value) {
$line_out = str_replace ("%$name%",
$value, $line_out);
}
}
return $line_out;
fclose ($file);
}
Hope that helps..
-Dan Joseph