douren7179 2016-06-03 14:02
浏览 113

str_replace使用php替换html内容

i'm creating a html editor using JavaScript and php, where the user selects html element from browser, edits this element inline and submits the changes to the server.

Now to apply the changes, i've used str_replace to compare the changes sent by the user with existing content in the html file at server end and replace it.

The selected element's content($_POST['content1']) and new content($_POST['contentreplace1']) are sent using $_POST But this functionality is not working properly. The existing code is not getting replaced with the new one.

<?php
        $orig="".trim($_POST['content1']);
        $new="".trim($_POST['contentreplace1']);

        $file = 'index.html';
        $file_contents = file_get_contents($file);
        $file_contents_new = str_replace($orig,$new,$file_contents);
        file_put_contents($file,$file_contents_new);
?>

What I'm doing wrong here?

Any suggestions or recommendations are welcomed. Please share your thoughts and experiences. Thanks for all the help in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?