This question already has an answer here:
I have a form allowing users to enter in their referral link (URL). I need to be sure they entered the http:// first before the url. If they entered it then it's ok, if they did not enter it then I need to add it before placing the url in the database.
How can I check this in PHP before saving the form in the database?
</div>
Use substr (and don't forget "https://" and "//") :
<?php
$url = 'example.com'; // Here is the URL you got in input
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://')
$url = 'http://'.$url;
else if (substr($url, 0, 2) == '//') // "//" is valid, it just means that the browser needs to continue using http or https depending on what it is currently using
$url = 'http:'.$url;