我知道我问了一个类似的问题,但这种做法更为笼统。有没有办法将div(带有确定的类)内容保存到文本文件,当前目录,服务器端,以及不需要用户点击的内容,因为我有500多个页面来保存同样的div,每一天。它可以在php中(如果在主页中使用,解析其他html文件),jquery,ajax,任何东西。
页面看起来像这样
...
<div class="myClass">
*lots of stuff*
*lots of stuff*
*lots of stuff*
</div>
...
并且每个页面都有一个不同的名称,例如:475.html,它会输出到475.txt .myclass div。在这个div中,我有更多的div,some,uls,lis等等。
我不知道ajax,我知道一点点PHP,还有一些jQuery。 但我知道,单独的jscript不会让你出于安全原因访问文件系统。 所以,如果可能的话,要非常清楚,并把我弄成一条路。
谢谢:)
答案 0 :(得分:0)
$fileName = $_SERVER['REQUEST_URI']; // Gets the filename
$fileName = str_replace('/',"",$fileName); //removes "/" string
$fileName = str_replace('.html',"",$fileName); //removes ".html" string
$myFile = "$fileName.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = '<div class="myClass">............';
fwrite($fh, $stringData);
fclose($fh);
是你想要的吗?