MrXander Posted September 13, 2007 Share Posted September 13, 2007 Hi there, I am trying to check a user inputted link to make sure it has http:// in it, but the code I have seems to throw a wobbly... if(preg_match("/http:\/\//", $link)) { $errorMessage = "There is no error..."; } else { $errorMessage = "<br>Your link appears to be invalid. Please confirm that your link contains 'http://' at the start."; } Any hints? Link to comment https://forums.phpfreaks.com/topic/69228-preg_match-problems/ Share on other sites More sharing options...
MrXander Posted September 13, 2007 Author Share Posted September 13, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/69228-preg_match-problems/#findComment-347925 Share on other sites More sharing options...
effigy Posted September 13, 2007 Share Posted September 13, 2007 Try the pattern %^http://%. Link to comment https://forums.phpfreaks.com/topic/69228-preg_match-problems/#findComment-347926 Share on other sites More sharing options...
GingerRobot Posted September 13, 2007 Share Posted September 13, 2007 It appears to be fine to me, are you sure you are echoing $errorMessage? The only thing i'd do is make a slight change to your pattern: if(preg_match("/^http:\/\//", $link)) { This ensures that http:// is found at the start of the string, rather than anywhere in it. Link to comment https://forums.phpfreaks.com/topic/69228-preg_match-problems/#findComment-347930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.