ereg() not working but preg_match() is...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ZeroFear
Forum Newbie
Posts: 14
Joined: Tue Feb 14, 2006 10:47 pm

ereg() not working but preg_match() is...

Post by ZeroFear »

i have this peice of code which does not seem to ever work ( the if statement is never true, thus the inner code never executes ).

if (ereg('<td\\sclass="vaText">\\s?([A-Z][A-Z\\s.]+)<', $subject, $regs)) {
echo "hello world";
}


but when i do:

if (preg_match('/<td\\sclass="vaText">\\s?([A-Z][A-Z\\s.]+)</', $subject, $regs)) {
echo "hello world";
}


then it will work...

If it helps at all, im using php 4.4.1 i belive

PS: also, for the second peice of code, how would i echo out the contents of the $reg array, i try

echo "$reg[1]";

but it comes up as blank, when i do sizeof on it, it comes back as 3. so it should be printing out whats in the () of the regexp.

any help would be great :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Last I checked, ereg_* was POSIX based and as such does not support the \s metacharacter, but [:space:] instead. I would highly suggest using preg_* anyways as they are the only regex supported in PHP 6 and are often faster than ereg_*.


Please use the syntax highlighting provided by

Code: Select all

for php code.
Post Reply