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
[SOLVED] which function do i use for a regular expression
Moderator: General Moderators
you totally did not answer anything he asked,HaxXxess wrote:1)what function do i work with in PHP with regular expression
You could use
echo "Hello World";
or
print ("Hello World");
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.";
}
?>Code: Select all
<?php
preg_match('/^[0-9]*$/i', $string);
?>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
perhaps if u wanted to avoid regEx, check this page out
http://us2.php.net/manual/en/function.ctype-digit.php
good luck