Latest news
Home » PHP » Check whether url contains http or https using php

Check whether url contains http or https using php

Sometimes the programmer need to identify the link contains http or https. Using php code can do this easily.

First store the string to a php varible- $URLstring=”http://smarttips.in/smarttips_logo.jpg”;

Second use the substr() function to find the occurrence of http or https -substr($URLstring, 0, 7)

<?php

$fromUrl =’0′;
$URLstring=”http://smarttips.in/smarttips_logo.jpg”;
if(substr($URLstring, 0, 7) == “http://”) { $fromUrl = “http”;

}
else if(substr($URLstring, 0, 8) == “https://”) {
$fromUrl = “https”;
}
?>

from the above code the $fromUrl  variable returns the result.

Leave a Reply

x

Check Also

How to print Codeigniter upload error

if you want to display errors on upload functionality in codeigniter. Use the following function ...