PDA

View Full Version : preg_replace



neo_philiac
12-22-2008, 04:36 PM
Can some one explain this to me ?


$rg_link_http = "h(ttps?://" . $rg_url . ")";

$CON = preg_replace('#\[([^\]]+)\|' . $rg_link_http . '\]#U', '<a href="xx$2" class="url">$1</a>', $CON);

I know this is parsing the line:


[Google|http://www.google.com]

to html code :


<p><a href="http://lionwiki.0o.cz" class="url">LionWiki</a> </p>



But what if I want to add another variable so that if it exists, it will add it to the variable ?

So, if I wanted the to give


[Google|http://www.google.com|onMouseover="ddrivetip('Visit this google page')"; onMouseout="hideddrivetip()]

It will make the link like this:


<a href="www.google.com" onMouseover="ddrivetip('Visit this google page')"; onMouseout="hideddrivetip()">Search Engine</a>

as you can see it just added the third variable parsed by | to the href tag.


It can be done with just one line but I dont know how - Please help :D