Page 1 of 1

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

Posted: Thu Jul 20, 2006 11:57 pm
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

Posted: Fri Jul 21, 2006 12:21 am
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.