Miscellaneous
|
|
|
|
<?php
function replace($str)
{
global $art;
if($nr1=strpos($str,'{')) // a database fields
{
$tr=substr($str,0,$nr1);
$nr2=strpos($str,'}',$nr1);
$tr.=$art[substr($str,$nr1+1,$nr2-$nr1-1)];
$tr.=substr($str,$nr2+1);
return replace($tr); // and maybe some more to do
}
elseif($nr1=strpos($str,'[')) // a link or something
{
$tr=substr($str,0,$nr1);
$nr2=strpos($str,']',$nr1);
$tr.=$GLOBALS[substr($str,$nr1+1,$nr2-$nr1-1)];
$tr.=substr($str,$nr2+1);
return replace($tr); // and maybe some more to do
}
else
{
return $str; // nothing to do.
}
} ?>
|
|
|
Usage Example
|
Source:
<?
$art["name"]="Elvis";
replace("Hi [name] how are you?"); ?>
Output:
Hi Elvis how are you?
|
|
|
Rate This Script
|
|
|
|