[SOLVED] which function do i use for a regular expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

which function do i use for a regular expression

Post 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
HaxXxess
Forum Newbie
Posts: 4
Joined: Sat Jul 24, 2004 4:28 pm

Post by HaxXxess »

1)what function do i work with in PHP with regular expression

You could use

echo "Hello World";

or

print ("Hello World");
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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);
?>
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thanks to bo of u
good to know of the ctype:)

and "HaxXxess" what u wrote was suppose to be a joke?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]is_numeric[/php_man]() works as well.
Post Reply