Can't make PHP eregi acknolwedge that newlines are ok

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
kirilisa
Forum Commoner
Posts: 28
Joined: Fri Dec 05, 2003 4:41 pm

Can't make PHP eregi acknolwedge that newlines are ok

Post by kirilisa »

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);
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. ereg* is slower than preg*
  2. to match line-feeds and carriage returns, you need to use a double quote string.. or use the preg function modifier 's'
Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url]
Post Reply