Page 1 of 1

explode on \n

Posted: Mon Jan 30, 2006 12:01 pm
by shiznatix
Am I just not seeing it? Why can I not explode on a \n? I know 100% that its there cause it comes out of the db and i know it has it in the db and when i <pre>print_r($arr)</pre> it has the line break and when i view source it does as well but when I explode on it, nothing happens.

Code: Select all

$fields = explode(' \n ', $info[1]);

echo 'fields';
$this->dump($fields);
/*
* [0] => Field 3 = params 3  
*            Field 4 = params 4  
*/
thats what happens. Any help? I really would like to keep the \n but even more so need somthing to explode on to seperate the 2 parts there.

Posted: Mon Jan 30, 2006 12:10 pm
by jayshields
Have you tried cutting out the spaces around the \n and also trying it in double quotes instead of single?

I have been able to explode on \n before without any hassle so it must be simple :)

Posted: Mon Jan 30, 2006 12:15 pm
by sheila
You need double quotes around the \n

Code: Select all

$fields = explode("\n", $info[1]);

Posted: Mon Jan 30, 2006 12:24 pm
by Chris Corbyn
If you want to keep the \n how about this? It's OS independent too.

Code: Select all

<?php
$parts = preg_split('/$/m', $string);
?>
EDIT | Ah yes, I should have read the responses better.... string literal won't parse \n ;)

Posted: Mon Jan 30, 2006 1:00 pm
by shiznatix
stupid double quotes. makes sence though. too much coding for one day thanks for the responces