将 textarea 输出显示为带有项目符号的列表 [英] Display textarea output as a list with bullets
问题描述
我有一个带有 textarea
的表单,我的客户在其中写入了几个短语/句子,通常每个短语/句子跨越一两行,然后他们按返回键插入换行符/开始下一句.
I have a form with a textarea
into which my clients write several phrases/sentences of which typically each one spans one or two lines, and they press the return key to insert a linebreak / begin the next phrase.
理想情况下,当此文本从数据库中提取并显示在网页上时,它应该具有某种列表格式,即每个短语开头的项目符号或 -
字符.
Ideally, when this text is fetched from the database and displayed on the webpage, it should have some kind of list format, i.e. a bullet or a -
character at the beginning of each phrase.
所以它应该看起来像一个带有 ul
和 li
的典型列表.但是在纯 textarea 字段中,您只能换行,不能格式化.我使用 nl2br($mytext)
将这些转换为换行事件到输出中的 <br>
标签.但是有没有类似的东西可以将整个文本转换成一个列表或列表项(li
)?
So it should appear like a typical list with ul
and li
. But in a plain textarea field you can only do a new-line, no formating. I use nl2br($mytext)
to convert these to new-line events to <br>
tags in the output. But is there anything similar to convert the whole text into a list or list items (li
)?
我知道我可以使用 TinyMCE 并让他们格式化,但我不希望他们格式化任何东西,我只希望将这些分隔行显示为列表.
I know I could use TinyMCE and let them format it, but I don't want them to format anything, I only want these separated lines displayed as a list.
我想过在 br
标签中添加包含项目符号的 :before
伪元素,但这些是行尾,而不是开头 - 不起作用...有什么想法我可以做什么吗?
I thought about adding :before
pseudo elements containing bullets to the br
tags, but those are the end of the lines, not at the beginning - won't work... Any ideas what I could do?
推荐答案
用新行拆分字符串并用 '
.
Split the string by new lines and implode it with '<ul><li>' . implode('</li><li>', $string) . '</li></ul>'
.
这篇关于将 textarea 输出显示为带有项目符号的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!