This PHP  code gives you ability to count total number of URLs available in any given string

<?php
function url_counter($myString)
{
if($myString!='')
{
$c1 = substr_count($myString, "www");
$c2 = substr_count($myString, "http://");
$c3 = substr_count($myString, "http://www");
$c4 = substr_count($myString, "https://");
$c5 = substr_count($myString, "https://www");
if($c3!=0)
{
$c1-=$c3;
$c2-=$c3;
}
if($c5!=0)
{
$c1-=$c5;
$c4-=$c5;
}
$total_url=$c1+$c2+$c3+$c4+$c5;
echo "<center>";
echo "<h2>URL counter Script</h2>";
echo "<b>My String: </b>$myString";
echo "<br/><br/>Total URL in string: <b>".$total_url."</b>";
echo "</center>";
}
}
$String="This is <u>www.link1.com</u> & <u>http://www.link2.com</u>";
url_counter($String);
?>