+ Reply to Thread
Results 1 to 6 of 6

Thread: Ereg and eregi
      
   

  1. #1
    Phoubers's Avatar
    Phoubers is offline Sergeant
    Join Date
    Oct 2007
    Location
    :D
    Posts
    34

    Question Ereg and eregi

    Hi,
    I read a few articles on ereg and eregi, but im having trouble understanding this. I saw a few examples such as

    ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

    and

    ([[:digit:]]|[~`!@#$%^&*()_=+{}|\:;"/?,]|[|]|-)+

    and so on..can someone help me break this down?
    No its not Fowbers its foobers :D

  2. #2
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: Ereg and eregi

    As you probably know from your articles, ereg and eregi are functions that search a string for a defined variable or group of variables Once found, then you create code to do something.

    For instance. Lets say you wanted to check your e-mail to make sure that it had the standard format of blahblah@whatever.com
    So you have to create a block of what is exceptable to meet that standard and test for it.
    If(! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
    {
    Do what ever here;
    }

    So the code above says
    IF the sting in $email does not have letters or numbers plus and @ symbol followed by a . and then followed by a set of letters or numbers followed by .com - DO what ever here

    So- in nut shell, it allows you to test a string and make sure it conforms to your own needed criteria.

    The difference between ereg() and eregi(). ereg() does a case sensitive search and eregi() is a case insensitive.

    Andy
    PHP- is a blast!

  3. #3
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: Ereg and eregi

    Just to add a little more.. both use a format called regex to check a string for certain characters

    if you are looking for more of a breakdown of what does what, I did a google search and this might help

    http://ysomeya.hp.infoseek.co.jp/eng-quick_regex.html

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

  4. #4
    Phoubers's Avatar
    Phoubers is offline Sergeant
    Join Date
    Oct 2007
    Location
    :D
    Posts
    34

    Default Re: Ereg and eregi

    ok let me see if I got this.

    If(! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))

    ereg means that the search is case sensitive (' starts the function [ starts the first set of characters A-Za-z0-9_- is allowing only characters A-Za-z0-9_- ] ends the first set +\@ means that the @whatever is next +/. means after @whatever they must have a . then [A-Za-z0-9_-] is com, so what we have so far is blahblah24@whatever.com, correct? then the +', $email means that this function is for the $email variable only? then of course the closing '))

    Thnx
    Matt
    No its not Fowbers its foobers :D

  5. #5
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: Ereg and eregi

    Bravo! Couldn't have done better myself.

    Andy
    PHP- is a blast!

  6. #6
    Phoubers's Avatar
    Phoubers is offline Sergeant
    Join Date
    Oct 2007
    Location
    :D
    Posts
    34

    Default Re: Ereg and eregi

    Ok well it seems to have worked thanks a lot!
    Matt
    No its not Fowbers its foobers :D

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49