steviez Posted January 15, 2008 Share Posted January 15, 2008 Hi, I have a field on my site where users enter a URL, i need it to make sure that http:// has been entered. How do i check for ths with preg_match? Thanks Link to comment https://forums.phpfreaks.com/topic/86222-solved-preg_match/ Share on other sites More sharing options...
dooper3 Posted January 15, 2008 Share Posted January 15, 2008 Why not use substr();? $url=http://www.google.com; if (substr($url, 0, 7) != "http://") { echo ("You didn't enter http://"); } Hope that helps. Link to comment https://forums.phpfreaks.com/topic/86222-solved-preg_match/#findComment-440413 Share on other sites More sharing options...
KrisNz Posted January 15, 2008 Share Posted January 15, 2008 $userInput = 'www.google.com'; //strpos way (faster) $pos = strpos($userInput,"http://"); if ($pos !== 0) { echo "you didnt enter http://"; } //regex way if (!preg_match("/^http:\/\//",$userInput)) { echo "you didn't enter http://"; } Link to comment https://forums.phpfreaks.com/topic/86222-solved-preg_match/#findComment-440418 Share on other sites More sharing options...
steviez Posted January 15, 2008 Author Share Posted January 15, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/86222-solved-preg_match/#findComment-440434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.