php自动生成txt php自动的把一个div标签里的内容生成txt.是一行一个的,txt里也保存成一行一个并把空格去掉这要怎么写啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 div标签在浏览器里,php 如何拿得到? div直接在php下面的html里面命名为<div id=txt> 加一个按钮,通过ajax获取该div内容,回调到后端再fwrite就可以了 $con=file_get_contents('你的php文件'); 再遍历div写入文件。 可以直接放在一个文件php里吧 你要想办法把div标签传到php端。一个文件不好操作。建议分开写。 如果div内容少,可以用此方法,大数据量不建议用。如果可以,你还是将div的内容从后台显示,那么就可以在浏览器显示前,将内容写入文件。<!-- xxx.php --><?phpif(isset($_GET['save'])){ file_put_contents($_GET['save']);}?><script language="javascript">var xmlHttp; function createXMLHttpRequest() { if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } }function saveDiv(){ createXMLHttpRequest(); var info=document.getElemntById("info").innerHTML; url = "xxx.php?save="+info+"&ran="+Math.random(); method = "GET"; xmlHttp.open(method,url,true); xmlHttp.onreadystatechange = function(){alert("已保存");}; xmlHttp.send(null); }</script><form id="sendlist" name="sendlist" action="xxx.php" method="post"> <input type="button" name="save" value="保存" onclick="saveDiv()" /> <div id="info"> aaaaaaaaa bbbbbbbbb </div></form> 500个div内容哪里来的?不可能凭空来的吧。将数据录入数据库,然后从数据库中调用数据多方便,调出来的数据随你怎么改。 一般的页面数据都是从数据库或文件中读出来,然后才于前端显示的。读取相对比较快。如Apache+mysql+php Netbeans链接远程数据库问题 php5.3以下没有vc9 接收不同name的文本框 Block with name "XXX" does't exist是什么问题 以前是用asp做开发的/现在有工程需要用php做/问在一周内怎么最快的学好php PHP的计数器问题? 数据库权限设置问题 取得 HTTP 变量值问题 php的安装问题 怎样,才能对一个文本文件进行查找,替换,删除等操作呢? 安装WampServer2.1a-x32打开phpmyadmin出现问题 单例模式的应用问题
命名为<div id=txt>
如果可以,你还是将div的内容从后台显示,那么就可以在浏览器显示前,将内容写入文件。<!-- xxx.php -->
<?php
if(isset($_GET['save'])){
file_put_contents($_GET['save']);
}
?>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest() {
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function saveDiv(){
createXMLHttpRequest();
var info=document.getElemntById("info").innerHTML;
url = "xxx.php?save="+info+"&ran="+Math.random();
method = "GET";
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = function(){alert("已保存");};
xmlHttp.send(null);
}
</script>
<form id="sendlist" name="sendlist" action="xxx.php" method="post">
<input type="button" name="save" value="保存" onclick="saveDiv()" />
<div id="info">
aaaaaaaaa
bbbbbbbbb
</div>
</form>
如Apache+mysql+php