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
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Mon Jan 30, 2006 12:01 pm
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.
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Mon Jan 30, 2006 12:10 pm
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
sheila
Forum Commoner
Posts: 98 Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas
Post
by sheila » Mon Jan 30, 2006 12:15 pm
You need double quotes around the \n
Code: Select all
$fields = explode("\n", $info[1]);
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Mon Jan 30, 2006 12:24 pm
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
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Mon Jan 30, 2006 1:00 pm
stupid double quotes. makes sence though. too much coding for one day thanks for the responces