Javascript使用document.write(str)进行输出时,常提示下列错误:
Error: unterminated string literal。 通常原因是输出字符str中包含换行符导致的。
解决方法如下:
asp:
str=replace(str,vbcrlf,"",1,-1,1)
php:
$str = str_replace("/n", "", $str);
$str = str_replace("/r", "", $str);
然后再进行document.write(str)输出。
注:
jsp的对应函数:
public static final String htmlToCode(String s)
{
if(s == null)
{
return "";
} else
{
s = replace(s, "", "/n/n");
s = replace(s, "", "/r/n");
s = replace(s, " ", "/t");
s = replace(s, " ", " ");
s = replace(s, "<", "<");
s = replace(s, ">", ">");
s = replace(s, "&", "&");
return s;
}
}