p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Understanding ereg() as used on p. 266


Message #1 by "Arnold Matthews" <arnoldm@m...> on Wed, 24 Jan 2001 22:50:39 -0000
In the line on p. 266:



if (ereg("[0-9]+", $val, $regs)) $total += $regs[0];



I understand ereg() just fine but do not understand the significance of:



[0-9]+ or  += used in the ereg() function



Also in the php on line manual the [0-9]{4}, [0-9]{1,2}etc. is also a

mystery:



if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {

    echo "$regs[3].$regs[2].$regs[1]";

} else {

    echo "Invalid date format: $date";



Thanks for help on this, Arnold Matthews

Message #2 by "Arnold Matthews" <arnoldm@m...> on Thu, 25 Jan 2001 18:11:05 -0000
I have found the solution to my own question about ereg() character

strings.  Being new to PHP and not having used Perl etc., I did not know

where to look at first.  The key seems to be "Character Classes". 

Information in Beginning PHP p. 246 p.p. , Professional PHP p.190 p.p.  

and a good discussion in a book called "PHP Developer's Cookbook" p. 124

p.p. clarifies the issues.



Arnold Matthews


  Return to Index