Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.