Page 1 of 1

which function do i use for a regular expression

Posted: Sat Jul 24, 2004 4:13 pm
by pelegk2
1)what function do i work with in PHP with regular expression
2)how do i check that my string contains only 0-9 ?
thnaks in advance
peleg

Posted: Sat Jul 24, 2004 4:28 pm
by HaxXxess
1)what function do i work with in PHP with regular expression

You could use

echo "Hello World";

or

print ("Hello World");

Posted: Sat Jul 24, 2004 4:42 pm
by tim
HaxXxess wrote:1)what function do i work with in PHP with regular expression

You could use

echo "Hello World";

or

print ("Hello World");
you totally did not answer anything he asked, :wink:

preg_replace(), preg_match() is the most common(PCRE perl), check it out at php.net, also ereg_replace is common.

to see if a string is 0-9 is simple.

Code: Select all

<?php
if (ereg('[0-9]', $string)) {
 echo "match was found.";
} else {
 echo "match not found.";
}


?>
or:

Code: Select all

<?php
preg_match('/^[0-9]*$/i', $string);
?>

Posted: Sat Jul 24, 2004 4:51 pm
by tim
also come to think of it

perhaps if u wanted to avoid regEx, check this page out

http://us2.php.net/manual/en/function.ctype-digit.php

good luck

Posted: Sat Jul 24, 2004 5:06 pm
by pelegk2
thanks to bo of u
good to know of the ctype:)

and "HaxXxess" what u wrote was suppose to be a joke?

Posted: Sat Jul 24, 2004 10:44 pm
by feyd
[php_man]is_numeric[/php_man]() works as well.