0

I have a problem with text that have new lines.. I insert text in my database like this:

$descrizionetipologia = mysql_real_escape_string($_POST['descrtipologia']);
//insert query

and I take it from the database with

 $descrizionetipologia=mysql_result($risultati,$i,"CA_DescrTipologia");
 //and I have to show it in a textarea with a javascript function.
 document.EDITform.EDITdescrtipologia.value="<?php echo $descrizionetipologia; ?>";

When I set the value of my textarea with $descrizionetipologia, the textarea don't show anything if the text have newline... I added nl2br , mysql_real_escape_string, but I have a lot of confusion about these functions...

if, when I want to show it, I use

$descrizionetipologia=str_replace(array("\r\n", "\n"),"",nl2br(htmlentities($descrizionetipologia)));

I see

PROVA <br> PROVA

but I don't want this...I want the text with new line... I want see

PROVA
PROVA

How can I do this?

4

1 回答 1

2

不要设置 textArea 的值 - 忽略换行符作为空格。而是设置 innerHTML 属性。

document.EDITForm.EDITdescrtipologia.innerHTML = "<?php echo addslashes ($descrizionetipologia); ?>";

(如果它包含引号,则添加斜杠)。这应该够了吧。

于 2014-10-07T08:22:37.963 回答