Can't make PHP eregi acknolwedge that newlines are ok
Posted: Mon Mar 21, 2005 1:16 pm
I made a little function to test if some string is 'alpha extended". The function is below, and should give the ok on strings that contain:
any letters, any numbers, / . , ( ) \ # % & - _ and any whitespace.
public static function isAlphaExtended($s) {
return eregi('^[\sA-Za-z0-9/\.\(\), \\#%&-_]+$', $s);
}
The problem is, this fuction tells you that your string is no good if there is a carriage return. I put in \s to indicate any whitespace ok, I even tried getting rid of the \s and putting in \r\n instead since in the past php hasn't always been ok with those 'combo' regex things, but no dice. No matter what it will not accept my newline.
How do I eregi for a newline? I tried making a tiny function that only matches whitespace and new lines but that doesnt' work either!
public static function isAlphaExtended($s) {
return eregi('^[\n\r ]+$', $s);
}
any letters, any numbers, / . , ( ) \ # % & - _ and any whitespace.
public static function isAlphaExtended($s) {
return eregi('^[\sA-Za-z0-9/\.\(\), \\#%&-_]+$', $s);
}
The problem is, this fuction tells you that your string is no good if there is a carriage return. I put in \s to indicate any whitespace ok, I even tried getting rid of the \s and putting in \r\n instead since in the past php hasn't always been ok with those 'combo' regex things, but no dice. No matter what it will not accept my newline.
How do I eregi for a newline? I tried making a tiny function that only matches whitespace and new lines but that doesnt' work either!
public static function isAlphaExtended($s) {
return eregi('^[\n\r ]+$', $s);
}