Jump to content

preg_match() problems


MrXander

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.