Thx all -----Oorspronkelijk bericht----- Van: Ivo F.A.C. Fokkema [mailto:I.F.A.C.Fokkema@xxxxxxx] Verzonden: dinsdag 8 augustus 2006 16:17 Aan: Reinhart Viane CC: php-general@xxxxxxxxxxxxx Onderwerp: RE: break up variable and put each element in an array On Tue, 2006-08-08 at 16:06 +0200, Reinhart Viane wrote: > > try this: > > > > $string = "3/01/2005 29/12/2005 2/01/2006 20/02/2006 28/12/2006 1/01/2007 > > 15/02/2007"; > > $array = explode(' ', $string); > > foreach ($array as $value) echo "Date: $value<br />"; > > If the user separates the dates by an enter in the textarea, you need to > explode on "\r\n". To be able to handle both, you need to use split() or > preg_split(). > > > When I use > $datelist=$_POST[datelist]; > $string=explode('\r\n',$datelist); > echo $string; > foreach ($string as $value) { > echo "Date: $value<br>\n"; > > this is what I get: > ArrayDate: 24/12/2018 26/12/2018 31/12/2018 14/02/2019 14/03/2019 20/06/2019 > 24/06/2019 26/06/2019 27/06/2019 27/06/2019 You'll need to use "\r\n", with double quotes. Single quotes don't interpret the \r\n the same. > This solved the issue, although I find it rather bizar: > $datelist=$_POST[datelist]; > $string=preg_split('/\r\n/', $datelist, -1, PREG_SPLIT_OFFSET_CAPTURE); > echo $string; > foreach ($string as $value) { > echo "Date: $value<br>\n"; > } > > Btw the input is a copy/paste from within a program > Thx all You might also want to try: $string=preg_split('/\s+/', $datelist); which would split on any (one or more) whitespace character(s). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php