explode line breaks

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

explode line breaks

Post by m2babaey »

Hi
I know we can use function explode to devide texts/strings into peices. And i know we use ln2br() to show line breaks when pulling out a text from the database.
what i need is exploding a text on line breaks.
to be more specific, users enter their keyword in a textarea and type each phrase in 1 line. I save that textarea content in 1 field but since I need to analize each phrase, I want to devide that text into keyword phrases when i use SELECT to pull it out
how can I do that?
thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$lines = explode(PHP_EOL, $content);

echo '<pre>';
print_r($lines);
Simple as that
dirkr
Forum Newbie
Posts: 20
Joined: Sat Jul 07, 2007 2:55 pm

Post by dirkr »

why not just explode("\n",$content) ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Line breaks differ between operating systems
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

*nix is \r\n
windows is \n

or the other way around. this covers both bases :)
Post Reply