FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to use these regular expressions





imagefree
I have widely used regular expressions in .htaccess, but cant in php.

here is

Code:
[0-9a-zA-Z_\-]+


what i want is that if a string $input doesnt match this pattern ,or contains any other character, just return false or similar.

you may convert the given expression in perl style.
i need it urgently. thanks.
leontius
Code:
function check($input) {
  return preg_match("#[0-9a-zA-Z_\\-]+#", $input);
}


Should be ok (not tested).
imagefree
Code:
function check($input) {
  return preg_match("#[0-9a-zA-Z_\\-]+#", $input);
}
echo check('abcdefgh/.,');

its not working. It echos 1.
rvec
1 = true
0 = false

Quote:
preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject . preg_match() returns FALSE if an error occurred.

http://nl2.php.net/preg_match
imagefree
rvec wrote:
1 = true
0 = false

Quote:
preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject . preg_match() returns FALSE if an error occurred.

http://nl2.php.net/preg_match


see a littlebit closely, the input should not match the pattern. Output should be false or 0.
Related topics
[JS] Regular expressions global match get first group
Searching MySQL Database
How to use ereg_replace to remove something?
Perl regex help
How?:Check the occurance of a certain character in a string.
Django or turbogears?
a regex help
Complicated regular expression (for preg_replace)
erm? what are these?
Help with regular expression
Automatic Regular Expressions!
Which language should I learn during my semester break?
Parsing XML Data using Regular Expressions
Learn Python from Google in 2 Days :D
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.