dongya2030 2013-09-20 16: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 17:24
    关注
            $breaks = array("
    ");
            $com = str_ireplace($breaks, "<br />", $com);
    

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

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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题