Array
(
[0] => first line
[1] => second line with a [url=http://www.site.com]text[/url] link
[2] => third line
[3] => fourth [url=http://www.site.com]link text2[/url] line with two of them [url=http://www.site.com]link text3[/url]
[4] => fifth line
)
original : 'first line'Array
(
[0] => first line
[1] => second line with a text link
[2] => third line
[3] => fourth link text2 line with two of them link text3
[4] => fifth line
)
//
// parseurls2.php
//
//VGR16062003 Création
//VGR21082009 ADDed code et enrobage
//
function AtomSubst($thestr, $DEBUG=FALSE) { // operates on a string
if ($DEBUG) echo "original : '$thestr'<BR>";
while (!($a=strpos($thestr,'[/url'))===FALSE) { // link found
$final=$a+strlen('[/url')+1;
$a=$a-1;
$b=$a-1;
while ($thestr[$b]<>']') $b--;
$thetext=substr($thestr,$b+1,$a-$b);
if ($DEBUG) echo "text= '$thetext'<BR>";
$a=0;
while (substr($thestr,$a,4)<>'url=') $a++;
$debut=$a-1;
$a=$a+4; // or strlen('searchedabove')
$theurl=substr($thestr,$a,$b-$a);
if ($DEBUG) echo "url= '$theurl'<BR>";
// rebuild string
$thestr=substr($thestr,0,$debut).'<a href="'.$theurl.'">'.$thetext.'</A>'.substr($thestr,$final); // rest
if ($DEBUG) echo "rebuilt : '".htmlspecialchars($thestr)."'<BR>";
} // while link found
if ($DEBUG) echo "final : '$thestr'<BR>";
return $thestr;
} // AtomSubst String Function
function SubstTag($par, $DEBUG=FALSE) {
$res=array(); // result
$n=count($par);
for ($i=0;$i<$n;$i++) $res[$i]=AtomSubst($par[$i],$DEBUG);
return $res;
} // SubstTag String[] Function
// test text
$yourmessage=array();
$yourmessage[]="first line";
$yourmessage[]="second line with a [url=http://www.site.com]text[/url] link";
$yourmessage[]="third line";
$yourmessage[]="fourth [url=http://www.site.com]link text2[/url] line with two of them [url=http://www.site.com]link text3[/url]";
$yourmessage[]="fifth line";
// display
echo 'source data :<BR>';
echo '<pre>';
print_r($yourmessage);
echo '</pre>';
// now call the SubstTag function
$result=SubstTag($yourmessage,TRUE); // turn to FALSE to get rid of debug messages
// display
echo 'result data :<BR>';
echo '<pre>';
print_r($result);
echo '</pre>';
for European Experts Exchange and Edaìn Works back to list of test scripts
Last update 2009-10-30 09:19:54
Copyright(©)(c) the respective authors. Licensed under the Creative Commons Attribution Share Alike 3.0 License
.
These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!