Announcement

Collapse
No announcement yet.

Ereg and eregi

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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!

    Comment


    • #3
      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


      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

      Comment


      • #4
        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

        Comment


        • #5
          Re: Ereg and eregi

          Bravo! Couldn't have done better myself.

          Andy
          PHP- is a blast!

          Comment


          • #6
            Re: Ereg and eregi

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

            Comment

            Working...
            X