wordwrap + nl2br =你需要换行吗?

时间:2009-11-16 17:08:44

标签: php html

我在表单中有一个textarea。没有提供html代码中的换行。 在php文件中(表单action = phpfile.php)我得到了textarea的值,如下所示:

$ad_text=wordwrap(nl2br($_POST['annonsera_text']), 47, '<br>', true);
echo $ad_text;

然后输出是:

hellohellohellohellohellohellohellohellohellohe
llohello.
hi.
hi.
hi.

/> hi.
hi.
hi.
hi.

/> 

并且textarea形式的原始输入是这样的:

hellohellohellohellohellohellohellohellohellohe
llohello.
hi.
hi.
hi.
hi.
hi.
hi.
hi.

在第三个\ n左右之后似乎有一个换行符,后跟一个'/&gt;'

任何想法为什么?

由于

1 个答案:

答案 0 :(得分:2)

wordwrap不会将<br>视为换行符 - 如果您在wordwrap之后移动nl2br它将按您的意愿工作,但您应该将wordwrap参数更改为“\ n”避免双倍间距:

$ad_text = nl2br(wordwrap($_POST['annonsera_text'], 47, "\n", true));