Heim  >  Artikel  >  Backend-Entwicklung  >  请教如何实现PHP修改html文件任意内容后保存原文件名

请教如何实现PHP修改html文件任意内容后保存原文件名

WBOY
WBOYOriginal
2016-06-23 13:39:101452Durchsuche

例如目前有个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>  <p><input type="submit" name="b1" value="修改"></p>  </form> </body></html>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn