$myString1="I often visit [B]<url>[/B]www.sitepoint.com/forums[B]</url>[/B]
and [B]<url>[/B]www.google.com[B]</url>[/B].";
$myString2="I often visit <url>[COLOR="Blue"]www.sitepoint.com/forums[/COLOR] [COLOR="Red"]sitePointForums[/COLOR]</url>
and <url>[COLOR="Blue"]www.google.com[/COLOR] [COLOR="red"]google[/COLOR]</url>.";
$myString1=preg_replace('/<url>(.*?)<\\/url>/s',
'<a href="http://$1">$1</a>', $myString1);
$myString2=preg_replace('/<url>(.*?) (.*?)<\\/url>/s',
'<a href="http://$1">$2</a>', $myString2);
echo $myString1.'<hr>';
echo $myString2.'<hr>';
[b]result[/b]
I often visit <a href="http://www.sitepoint.com/forums">www.sitepoint.com/forums</a>
and <a href="http://www.google.com">www.google.com</a><hr>
I often visit <a href="http://www.sitepoint.com/forums">sitePointForums</a>
and <a href="http://www.google.com">google</a><hr>
I can say blue parts are urls and red parts are link texts.
In myString2, there are spaces as delimiters between www.sitepoint.com/forums and sitePointForums or www.google.com and google which are inside the start <url> tag and the end </url> tag.
On the contrary, myString1 has no space between the start <url> tags and the end </url> tags.
In myString1, urls become directly link texts.
If I have myString3 which has links with delimiters and without delimiters like the below,
how can I make my target result below when a custom tag of <url> has space as a delimiter make the link text with the text after delimiter
and when a custom tag of <url> has no space make the link text with the url itself.
$myString3="I often visit [B]<url>[/B][SIZE="4"]www.sitepoint.com/forums[/SIZE][B]</url>[/B]
and [B]<url>[/B]www.google.com [SIZE="4"]google[/SIZE][B]</url>[/B].";
[b]result[/b]
I often visit
<a href="http://www.sitepoint.com/forums">[SIZE="4"]www.sitepoint.com/forums[/SIZE]</a>
and <a href="http://www.google.com">[SIZE="4"]google[/SIZE]</a><hr>