【问题标题】:wordwrap + nl2br = more than you need line breaks?wordwrap + nl2br = 超过你需要换行符?
【发布时间】:2009-11-17 01:21:55
【问题描述】:

我在表单中有一个文本区域。没有提供 html 代码中的换行。 在 php 文件(forms 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.

/> 

原来输入的文本区域是这样的:

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

第三个\n左右之后好像有个换行符,后面跟着一个'/>'

知道为什么吗?

谢谢

【问题讨论】:

    标签: php html


    【解决方案1】:

    wordwrap 不会将 &lt;br&gt; 视为换行符 - 如果您在 wordwrap 之后移动 nl2br,它将按您的意愿工作,但您应该将 wordwrap 参数更改为 "\n" 以避免双倍行距:

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

    【讨论】:

    • 如果没有 nl2br,每当用户点击“输入”并且有一个 NL 时,它就会被跳过并显示在一个长字符串中!
    • 啊,你需要运行 nl2br after wordwrap 然后
    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 2011-02-24
    • 1970-01-01
    • 2014-02-23
    • 2012-10-04
    • 1970-01-01
    • 2014-01-23
    • 2012-07-01
    相关资源
    最近更新 更多