How do I read a “,” as “<br />” in PHP/MySQL?

不想你离开。 提交于 2019-12-02 07:46:35

Assuming there are no CSV quoting issues:

$newStr = str_replace( ',', '<br>', $string );

EDIT:

After seeing your rollback, i see that you actually want to replace the , with a newline character such as \r, \n or \r\n:

$newStr = str_replace( ',', "\n", $string );
$str = 'asdf,asdf';
$str = str_replace(',','<br />',$str);

Do a php str_replace.

$final_data = str_replace(",","<br />",$row["data"]);

Use str_getcsv() to make sure the escaped commas are processed correctly.

Code:

$input = "hello,no,thanks";
$array = str_getcsv($input);
$result = implode("\n",$array);

Output

hello
no
thanks

Just use str_replace

$my_output = str_replace(",", "<br />", "no,thanks,text,text");

You could try the MySQL REPLACE function to have the data come back from your query already formatted like this:

Example:

select replace(column_with_commas_in_strings,',','<br />') as new_string
from some_table;

In your case, something like:

$result = mysql_query("SELECT replace(alias,',','<br />') as ALIAS FROM characters WHERE namn = 'Jargon'");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!