dongya2030 2013-09-20 08:34
浏览 79
已采纳

在php-posting脚本中将'enter'替换为<Br>标记

I'm aware that there are multiple examples of this within this forum and others, I've tried them all, but couldn't get either to work. I got a php-script that writes to a php-file, wich gets loaded within a php script.

My purpose is to get automatic br-tags into the php-post once people push 'enter'

<?php
        if ( isset( $_POST[ 'submit' ] ) ) {
        $com  = $_POST['txt'];
        If ($com === "") {
        echo "<font color=red><b>You must write something to post!</font></b>";
        die;
        }
        $time = gmdate("M d Y H:i:s",time()+(2*60*60));
        $com  = $_POST['txt'];
        $count = strlen($com);
        $com = stripslashes($com);
        $breaks = array("<br />","<br>","<br/>");
        $com = str_ireplace($breaks, "
", $com);
        $fp = $file = fopen( "NAME_OF_POST.php", "a");
        Multiple fwrites follows.....
        Multiple fwrites follows.....
        rewind($fp);
        fclose($fp);
        echo '<script type="text/javascript">window.location ="";</script>';
        }
        ?>

and it loads within:

<textarea name="txt" id="area" class="typo_vind" placeholder="......" tabindex="1"></textarea>

Anyone knows how to get linebreaks from enter to be replaced with br-tags?

In advance, than you :)!

  • 写回答

3条回答 默认 最新

  • dsh102123 2013-09-20 09:24
    关注
            $breaks = array("
    ");
            $com = str_ireplace($breaks, "<br />", $com);
    

    Switching places did the trick :) Thank you all:)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部