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? Quote 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? Quote 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://%. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/69228-preg_match-problems/#findComment-347930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.