Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 10-28-2007, 02:00 PM
Phoubers's Avatar
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 10-29-2007, 12:16 AM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,282
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
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 10-29-2007, 11:45 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,638
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 10-30-2007, 06:28 AM
Phoubers's Avatar
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 10-30-2007, 12:36 PM
Andy128's Avatar
Major General
 
Join Date: Dec 2005
Location: Michigan
Posts: 2,282
Default Re: Ereg and eregi

Bravo! Couldn't have done better myself.

Andy
__________________
My diamond in the rough - www.123gpp.com

* Click here for some BV tutorials (Php mailto Form, I-Frames, Picture display and much, much more!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 10-30-2007, 10:01 PM
Phoubers's Avatar
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 01:23 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

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 50 51 52 53 54 55