Re: Replace or regex?
| From: | Brian | Date: | Thu, 30 Sep 2004 14:57:28 +0000 |
| Subject: | Re: Replace or regex? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198278@lists.php.net to get a copy of this message | ||
$var="##testcode##this is a ##code1## test of the ##code2## code
replacement system ##code3##";
$varParsed=strParse($var);
echo "$var<br>";
echo $varParsed;
function strParse($origString)
{
while ( $offset<strlen($origString) &&
!(($foundBeg=strpos($origString, "##", $offset))===FALSE))
{
if (($foundEnd=strpos($origString, "##", $foundBeg+2))<>FALSE)
{
$tmpString=substr($origString, $lastEnd, $foundBeg-$lastEnd);
$tmpCode=substr($origString, $foundBeg+2, $foundEnd-($foundBeg+2));
$finalString=$finalString . $tmpString . "<a
href='somewhere.php?id=$tmpCode'>$tmpCode</a>";
$offset=$foundEnd+2;
$lastEnd=$foundEnd+2;
} else {
echo "Parse Error<br>";
break;
}
}
return $finalString;
}
On Thu, 30 Sep 2004 11:39:10 +0300, mario <developer@icop.gr> wrote:
> Hi all
>
> I have a string: ##CODE## and I want to replace that with <a
> href="somewhere.php?id=CODE">CODE</a>
>
> can u help?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>