Goldeneye Posted September 1, 2009 Share Posted September 1, 2009 I'm trying to split a blocks of text (separated by line-breaks) into an array. I tried this code: <?php /* $row['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed nisl tortor. Suspendisse potenti. Aenean venenatis scelerisque lacus sit amet ultrices. Suspendisse a lacus arcu, tincidunt auctor dui. Aenean nec felis erat, eu vestibulum enim. Integer lacinia imperdiet cursus. Nunc vitae iaculis lorem. Pellentesque eleifend dolor non erat dignissim sit amet gravida sem egestas. Donec euismod pellentesque lectus, ut facilisis libero vulputate eu. Praesent quis mauris sit amet nisl facilisis auctor ut non augue. Pellentesque sed neque diam. Sed egestas eros ut lorem tincidunt hendrerit. Aliquam dolor orci, cursus id suscipit ac, tincidunt nec augue. Duis pellentesque tortor vitae urna commodo ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent fringilla quam ut arcu venenatis ac commodo lectus viverra. Suspendisse potenti. Vivamus vitae eros leo.'; */ $query = $sql->query("SELECT `content` FROM `table` WHERE `id`=16"); $row = $sql->fetchAssoc($query); $p = explode("\n\n", $row['content']); ?> But it just puts the blocks on text into a single element (array(0 => $row['content'])) instead of loading the paragraphs into their own element. I should also mention that the type of field that stores `content` is LONGTEXT (if that helps at all). Edit: It's also worth mentioning that I escape the value of `content` before inserting it into the database. Any input would be greatly appreciate. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/172665-solved-splitting-paragraphs-into-an-array/ Share on other sites More sharing options...
trq Posted September 1, 2009 Share Posted September 1, 2009 Try... $p = explode(PHP_EOL, $row['content']); Quote Link to comment https://forums.phpfreaks.com/topic/172665-solved-splitting-paragraphs-into-an-array/#findComment-910118 Share on other sites More sharing options...
Goldeneye Posted September 1, 2009 Author Share Posted September 1, 2009 Ahhh yes, this works fine as it basically just explodes the string with "\n" (As I've tried this before). I'm trying to split double-line-breaks. "\n\n". Unfortunately, as I said before, it doesn't seem to want to work. Quote Link to comment https://forums.phpfreaks.com/topic/172665-solved-splitting-paragraphs-into-an-array/#findComment-910131 Share on other sites More sharing options...
JonnoTheDev Posted September 1, 2009 Share Posted September 1, 2009 \r is a carraige return Quote Link to comment https://forums.phpfreaks.com/topic/172665-solved-splitting-paragraphs-into-an-array/#findComment-910238 Share on other sites More sharing options...
Goldeneye Posted September 1, 2009 Author Share Posted September 1, 2009 Ahhh of course! I totally forgot about the Carriage-Return. I simply changed explode("\n\n", $row['content']) to explode("\n\r", $row['content']) and it appears to be working as I want it to, now. Thank you neil.johnson for that enlightenment. And thank you thorpe for your time. Quote Link to comment https://forums.phpfreaks.com/topic/172665-solved-splitting-paragraphs-into-an-array/#findComment-910510 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.