Results 1 to 3 of 3

Thread: What is the 3rd parameter?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default What is the 3rd parameter?

    This code is supposed to check if the URL entered in the form starts with http://, and add it if it does not.

    Code:
    if( !ereg("^http://*", $ev_url, $regs) ) {
    	$ev_url = "http://" . $ev_url;
    }
    It doesn't seem to be working. The parts I don't understand are:

    Code:
    ereg ("^
    and
    Code:
    $regs
    . I can find no $regs variable anywhere in the script.

    Anyone know the best way to check a URL submitted through a form before inserting into a table?

    Mahalo. erin

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    No need for regex.
    PHP Code:
    if(substr($URL07) != 'http://')
      
    $URL 'http://' $URL

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The regex-free version is preferable (don't use regular expressions if it's easily expressed in another way, since regular expressions are very expensive), but to explain your earlier version: ereg() is a function that works on regular expressions, ^ in a regular expression means to only match at the beginning of the string (or line with the multiline flag), and $regs is assigned to by the ereg() function — that parameter of ereg() is a reference.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •