开发者

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

开发者 https://www.devze.com 2023-03-10 10:51 出处:网络
So I have this MySQL database and a table and in the rows there a lot of \",\" in them, and I wish when they are output on the screen with PHP to b开发者_运维百科e switched to \"\" instead of coma, ho

So I have this MySQL database and a table and in the rows there a lot of "," in them, and I wish when they are output on the screen with PHP to b开发者_运维百科e switched to "

" instead of coma, how do I do that?

I mean, this is a example, it stands like this: hello,no,thanks and instead of being output like that I would like it to be output as: hello no thanks

How do I do that? Could someone do it for me? Would be very friendly.


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'");
0

精彩评论

暂无评论...
验证码 换一张
取 消