Jump to content

Recommended Posts

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.