所以我有这个MySQL数据库和一个表,行中有很多",",我希望当它们在屏幕上用PHP输出时,切换到"
"而不是昏迷,我该怎么做?
我的意思是,这是一个例子,它是这样的:你好,不,谢谢,与其这样输出,我希望它输出为:你好不感谢
我该怎么做?有人能帮我做吗?会很友好。
假设没有CSV引用问题:
$newStr = str_replace( ',', '<br>', $string );
编辑:
在看到您的回滚之后,我发现您实际上想要用newline
字符(如'r
、'n
或'r'n
:)替换,
$newStr = str_replace( ',', "'n", $string );
$str = 'asdf,asdf';
$str = str_replace(',','<br />',$str);
执行php str_replace。
$final_data = str_replace(",","<br />",$row["data"]);
使用str_getcsv()
确保正确处理转义逗号。
代码:
$input = "hello,no,thanks";
$array = str_getcsv($input);
$result = implode("'n",$array);
输出
hello
no
thanks
只需使用str_replace
$my_output = str_replace(",", "<br />", "no,thanks,text,text");
您可以尝试MySQL REPLACE函数,让数据从查询中返回,格式如下:
示例:
select replace(column_with_commas_in_strings,',','<br />') as new_string
from some_table;
在你的情况下,类似于:
$result = mysql_query("SELECT replace(alias,',','<br />') as ALIAS FROM characters WHERE namn = 'Jargon'");