0

我知道我问了一个类似的问题,但这更笼统。有没有办法将 div(具有确定的类)内容保存到文本文件中,在当前目录中,在服务器端,以及不需要用户单击的内容,因为我有 500 多个页面来保存相同的 div,每天。它可以是 php(如果在主页中使用,用于解析其他 html 文件)、jquery、ajax 等等。

页面看起来像这样

...
<div class="myClass">
*lots of stuff*
*lots of stuff*
*lots of stuff*
</div>
...

并且每个页面都有不同的名称,例如:475.html,它会将 .myclass div 输出到 475.txt。在这个 div 里面,我还有一些 div,一些,uls,lis 等等。

我不知道ajax,我知道一点PHP,和一些jQuery。但我知道,仅 jscript 不会让您出于安全原因访问文件系统。因此,如果可能的话,请非常清楚,并为我指明方向。

谢谢 :)

4

1 回答 1

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);

is that what you want?

于 2012-08-16T13:55:34.397 回答