PHP将逗号转换为< br/> [英] PHP turn comma into a <br />

查看:63
本文介绍了PHP将逗号转换为< br/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实知道php可以使用 <br /> > ,但是有没有办法将逗号(,)转换为<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将逗号转换为&lt; br/&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆