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

Export Database using codeigniter

Database Utility Class : CodeIgniter PHP script to download mysql db-codeigniter,Backup MySQL database with CodeIgniter ...