1

Here is code I have for a url validation function in CI, and this is the callback function

function valid_url($facebook)
    {
        $pattern = "/^((ht|f)tp(s?)\:\/\/|~/|/)?([w]{2}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?/";
        if (!preg_match($pattern, $facebook))
        {
            return FALSE;
        }

        return TRUE;
    }     

I'm getting this error

Message: preg_match() [function.preg-match]: Unknown modifier '|'
Jonathan
  • 1,542
  • 3
  • 16
  • 24
SoftwareDev
  • 336
  • 2
  • 13
  • Check out [RFC 3986](https://tools.ietf.org/html/rfc3986) for URL implementation. Check out [RFC 2396](https://www.ietf.org/rfc/rfc2396.txt) for URI implementation. Check out [SO post](http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) for examples. Check out [SO post](http://stackoverflow.com/questions/176264/whats-the-difference-between-a-uri-and-a-url) about difference between `URL` and `URI`. Make sure of percent encoded strings are properly matched too. – gwillie Jan 02 '15 at 02:41

1 Answers1

1

Try this

        function validate_url($url) {
        $data = trim($url);
        $data = stripslashes($url);
        $data = htmlspecialchars($url);
        return $url;


     // check address syntax is valid or not(this regular expression also allows dashes in the URL)
        if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) {
        return FALSE;
        } else {
    return TRUE;
    }
     } 
  $check =  validate_url($url);
Indra Kumar S
  • 2,818
  • 2
  • 16
  • 27