I have a string
$string = \'[URL=\"http://www.google.com\"]Google[/URL]
I am using the following code to convert it to html link
I think what you want is preg_match
?
Actually, you can just use the pattern you already have. It will give you the whole match and each match within round parantheses through a parameter.
preg_match('/\[url=(.+?)\](.+?)\[\/url\]/i', $string, $matches);
echo $matches[1]; // http://www.google.com
echo $matches[2]; // Google
echo $matches[0]; // [URL="http://www.google.com"]Google[/URL]
The return value of preg_match
is 1 (match found) or 0/false (no match/error).