PHP将逗号转换为< br/> [英] PHP turn comma into a <br />
问题描述
我确实知道php可以使用 ,
)转换为<br />
?
I do know that php can turn a newline into a <br />
using nl2br()
, but is there a way that it can turn a comma (,
) into a <br />
?
例如,在HTML页面上,用户输入一堆用逗号分隔的单词.然后,他提交了该文件,它像通常一样被发送到一个PHP文件,而不是将数据直接发送到数据库中,而是通过某种功能将其替换为<br />
.
For instance on an HTML page a user enters a bunch of words that are separated by a comma. He then submits it, it gets sent to a PHP file like normal and instead of the data getting sent right into the database, it goes through some kind of function to replace the commas with <br />
.
因此,如果我要在HTML页面上显示数据,那么他们输入的每一个由逗号分隔的内容现在都由换行符/换行符分隔?
So if I were to show the data on an HTML page, each thing they entered in that was separated by a comma is now separated by a newline/line break?
推荐答案
You can use a str_replace()
to replace any string by another, so also a comma with a <br />
:
$output = str_replace(',', '<br />', $input);
这篇关于PHP将逗号转换为< br/>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!