From <url> to <a> link

[b]code[/b]

<?php
$inputText="<url>www.sitepoint.com</url> and <url>google.com</url> are 
my favorite sites."

$urlProcess_inputText= $urlProcess(inputText);
?>

[b]target value of $$urlProcess_inputText[/b]

<a href="http://www.sitepoint.com">www.sitepoint.com</a> and 
<a href="http://google.com">google.com</a> are 
my favorite sites.


I like to change from <url> to <a> link like the above.

I guess the following is needed for it.

(1) count the number of "<url>" : 2 
<? strlen($inputText)-strlen(str_ireplace("<url>","<url",$inputText) ); ?>

(2) seperate the url value : www. sitepoint.com and google.com
(3) loop the myText 2 times : ~
and so forth.

Can I make it with your help?

With limited knowledge of regex :slight_smile:


$inputText="<url>www.sitepoint.com</url> and <url>google.com</url> are 
my favorite sites.";
echo preg_replace('/<url>(.*?)<\\/url>/s', '<a href="http://$1">$1</a>', $inputText);

Thank you, it works fine.