例如目前有个1.html文件,想用PHP程序把1.html里面的任意内容修改掉,然后保存
1.html 例如里面的内容有
11111111111222222222abc222222333333333333333333444444444444
就是想用PHP把1.html源码全部读取出来放在一个编辑框内,然后可以在里面任意修改内容后 ,点保存就保存起来。这个怎么实现?有点类似DEDE后台的模版文件修改那样,不过没有那么复杂。谢谢指教!
??完成後,提交?容?,需要把原?的文件路?也提交,
然後服?端直接file_put_contents(文件名,文件?容,true); 就可以了。
??完成後,提交?容?,需要把原?的文件路?也提交,
然後服?端直接file_put_contents(文件名,文件?容,true); 就可以了。
http://www.example.com/index.php?file=1.html
然後在同目?下?建一?1.html
index.php
<?php$file = isset($_REQUEST['file'])? $_REQUEST['file'] : '';if($file=='' || file_exists($file)==false){ echo 'file not exists'; exit();}$content = isset($_POST['content'])? $_POST['content'] : '';if($content!=''){ // 有修改 file_put_contents($file, $content, true);}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> New Document </title> </head> <body> <form name="form1" action="" method="post"> <p>文件?容</p> <p><textarea name="content" style="width:500px;height:300px;"><?php echo file_get_contents($file); ?></textarea></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1463">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680176337096.png" alt="图改改">
</a>
<div class="aritcle_card_info">
<a href="/ai/1463">图改改</a>
<p>在线修改图片文字</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="图改改">
<span>455</span>
</div>
</div>
<a href="/ai/1463" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="图改改">
</a>
</div>
<p><input type="submit" name="b1" value="修改"></p> </form> </body></html>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号