Mastodont Posted January 9, 2008 Share Posted January 9, 2008 Probably lamer question, but I really don't understand ... wanna break content of textarea into lines. This works OK, each item of array contains one line: $s = preg_split("\r?\n?", $_POST['...']); Array ([0] => first [1] => second [2] => third ) With delimiters, array is composed from individual characters :-((( $s = preg_split("/\r?\n?/", $_POST['...']); Array ([0] => [1] => f [2] => i [3] => r [4] => s [5] => t [6] => [7] => s [8] => e [9] => c [10] => o [11] => n [12] => d [13] => [14] => t [15] => h [16] => i [17] => r [18] => d [19] => ) WTF? Thanks for explanation. Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 9, 2008 Share Posted January 9, 2008 ~a?~ on: hi hi yields: Array ( [0] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) ) There are 6 characters including linebreaks in the haystack on an optional ? it will try to match it for each character in the haystack, and if not it will produce a null group/capture This is what it looks like.. So \r? which is not found in your haystack (which you did not provide so i'm guessing based on my testing) It gives captures all null for each char it checks against Also I noticed '\r?\n?' produces a parse php error that says it needs delimiters, while "\r?\n?" doesn't Here are some interesting notes on the function: http://us.php.net/manual/en/function.preg-split.php#59358 http://us.php.net/manual/en/function.preg-split.php#51209 Quote Link to comment Share on other sites More sharing options...
effigy Posted January 11, 2008 Share Posted January 11, 2008 Why would you use a pattern where everything is optional? Which type of line breaks do you need to look for? Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 13, 2008 Share Posted January 13, 2008 WTF? Thanks for explanation. Do you have an explanation for this behavior, effigy? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 14, 2008 Share Posted January 14, 2008 WTF? Thanks for explanation. Do you have an explanation for this behavior, effigy? Sheer confusion mixed with mainstream lingo? Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 14, 2008 Share Posted January 14, 2008 Sheer confusion mixed with mainstream lingo? so the reason why "\r\n" works as a pattern but this doesn't '\r\n' and why \r?\n? yields so many subgroups is because of sheer confusion & mainstream lingo? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 14, 2008 Share Posted January 14, 2008 I responded to what you quoted. "\r\n" works as a pattern but this doesn't '\r\n' '/\r\n/' works fine. You were missing delimiters. why \r?\n? yields so many subgroups Because everything is optional. Quote Link to comment Share on other sites More sharing options...
dsaba Posted January 14, 2008 Share Posted January 14, 2008 this does not provide a parse error and there are no delimiters in the pattern: preg_match("\r\n", 'hello world'); Quote Link to comment Share on other sites More sharing options...
effigy Posted January 14, 2008 Share Posted January 14, 2008 Are your errors turned on? I get the following: Warning: preg_match() [function.preg-match]: Empty regular expression in ... on line .... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.