I'd like to extract onclick="printcoupon('292')"
from this:
[url=http://stackoverflow.com?foo=bar|onclick=printcoupon('292')]foobarbaz[/url]
The text inside the onclick can change dynamically but what I was thinking of was detecting if there is a word onclick inside this and if so grab the contents inside the double quotes (currently it says printcoupon('292')
)
Basically though i need to grab either onclick=printcoupon('292')
or just printcoupon('292')
.
Either way, this is unfamiliar territory.
function bbcode($str) {
// situation when str = [url=http://stackoverflow.com?foo=bar|onclick=printcoupon('292')]foobarbaz[/url]
if(stristr($str,'onclick')){
$parts=explode('|',$str);
var_dump($parts);die();
$str=preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', '<a href="\1" style="text-decoration:none;color:#336699" onclick="PUT ONCLICK EXTRACTED CONTENT HERE">\2</a>', $str);
// situation when str = [url=http://stackoverflow.com?foo=bar]foobarbaz[/url]
} else {
$str=preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', '<a href="\1" style="text-decoration:none;color:#336699">\2</a>', $str);
}
return $str;
}
So as you can see,