Jump to content

[SOLVED] Regex noob confused about ereg


CaptainJester

Recommended Posts

I am trying to use ereg to see if an HTML field is just numeric or if characters were entered too.  The problem is I can't seem to get ereg to return the expected result.  When I put my expression and test into a webpage regex it returns the result I expect.  If I run a test program through PHP it doesn't return what I expect.  Here is my test code.

$source = "3889s";

$arr = array();

$result = ereg('/[^0-9]*/', $source, $arr);

echo "$source \n";
echo "count = $result\n";
print_r($arr);

I would expect this to return 1 result for finding the 's' in the source string, but this is the output I get.

3889s
count =
Array
(
)

 

Am I missing something?

Link to comment
https://forums.phpfreaks.com/topic/115914-solved-regex-noob-confused-about-ereg/
Share on other sites

Thanks.

 

I gave that a try and it still is not making a difference.  Here are the 2 outputs I am getting now.

3889s
count = 1
Array
(
    [0] =>
)

3889
count = 1
Array
(
    [0] =>
)

 

I am using PHP version 5.2.6 if that makes any difference.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.