0

Hi,

How would i have a text box where each new line is a bullet list.

<ul>
<li>method line 1</li>
<li>method line 2</li>
</ul>

Can i extract the HTML code tags with the text and insert it into a database with the code and text? So it can be accessed later from the database.

2
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by blocblue
0

If you want to take plain text from a textarea, and treat each new line as a separate bullet point, you could store the plain text in the database, and then parse the content as follows when retrieving it:

<?php $bullet_points = explode("\n", $plain_text); ?>

<ul>
<?php foreach($bullet_points as $bullet_point): ?>
    <li><?php echo $bullet_point; ?></li>
<?php endforeach; ?>
</ul>

If you're using this on a regular basis, you could wrap the functionality into a function.

Is this what you meant?
R.

0

Hi,

That is kind of what i want. But can i parse the content before sending it to the database so that it has the tags inside the database?

1

You can, but it's worth considering whether you will need to edit the list after it's been inserted into the database. If you do, then it would be more difficult to work around the HTML tags.

Anyway, to parse it before inserting:

$list = '<ul><li>' . implode('</li><li>', explode("\n", $plain_text)) . '</li></ul>';

R

Votes + Comments
good point wrt tags in DB
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.