Hi all,
My guess is I miss something really dumb, but here is my problem. I want to
use ereg to find some pattern, but it doesn't seems to work. The same pattern
uses with ereg_replace, works fine and replaced the pattern. Here is my code,
and the output:
<?
$string = "This is a %ANS[1] test, and %ANS[2] test, and %ANS[10], test";
echo "String is: $string\n";
$pattern = "%ANS[[0-9]+]";
$bool = ereg($pattern, $string, $regs);
echo "REGS is :\n";
print_r($regs);
echo "BOOL is $bool\n\n";
echo ereg_replace($pattern, "REPLACED", $string);
?>
// OUTPUT :
String is: This is a %ANS[1] test, and %ANS[2] test, and %ANS[10], test
REGS is :
Array
(
[0] => %ANS[1]
)
BOOL is 7
This is a REPLACED test, and REPLACED test, and REPLACED, test
// END OUTPUT
As you can see, ereg only catch the first one that match the pattern.
Furthermore, why is the return value of ereg 7? The doc says it returns a
boolean.
To clarify, I want to find everything that has a pattern
%ANS[x]
where x can be any number in any digit. It could be that my regexp is wrong,
since I am still not very good at it.
Any help will be greatly appreciated.
Thanks.
RDB
--
-------------------------------------------------
/"\ ASCII Ribbon Campaign against HTML
\ / email and proprietary format
X attachments.
/ \
-------------------------------------------------
Have you been used by Microsoft today?
Choose your life. Choose freedom.
Choose LINUX.
-------------------------------------------------
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php