Question

I have a small PHP script pulling information from an atom feed. What is the best way to then push that echo into a file or database? I want to be able to reference that information on an hourly basis.

So for example.

PHP grabs HTML page.
Webserver stores the resulting HTML locally.
Webserver references that locally stored HTML.
Webserver displays a template version of the local information.

Here's the php pulling the html:

<?php include('simple_html_dom.php'); echo file_get_html('http://www.website.com')->plaintext[1] ; ?>

No correct solution

OTHER TIPS

you can use file_put_contents() which is pretty simple. http://php.net/file_put_contents

file_put_contents("myFile", file_get_html('http://www.website.com')->plaintext[1]);

hope this will help uh...

<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php require'simple_html_dom.php'; ?>
<?php
    $url_path='http://www.google.com/';
    $create=fopen("folder/"."index.html",'w+') or die("can't open file");
    $src=file_get_html($url_path)->plaintext ;
    $write=fwrite($create,$src);
        fclose($create);

    foreach($html->find('script') as $script)   //get script 
            {

                    $scriptPath=$script->src;
                    $js = explode("/", $scriptPath);
                    $jsName = end($js);
             $path="";
                  for ($i=0;$i<(count($image)-1);$i++) 
                      {
                        $path .= $image[$i] . "/";
                        if(!file_exists('folder/'.$path))
                            {
                                mkdir('folder/'.$path, 0777, true);     //jquery folder created
                            }       
                      }
                    file_put_contents('folder/'.$path.$jsName,file_get_contents($url_path.$scriptPath)); //all jquery downloaded
            }

        foreach($html->find('img') as $img)     //image
                {

                    $imgpath=$img->src;
                    $image = explode("/", $imgpath);
          $path="";
                      for ($i=0;$i<(count($image)-1);$i++) 
                      {
                        $path .= $image[$i] . "/";
                        if(!file_exists('folder/'.$path))
                            {
                                mkdir('folder/'.$path, 0777, true);     //img folder created
                            }       
                      }

                    $imgName = end($image);
                        file_put_contents('folder/'.$path.$imgName,file_get_contents($url_path.$imgpath));  //img downloaded

                } 

        foreach($html->find('link') as $link)  //get link 
                {
                        if(strtolower($link->getAttribute('rel')) == "stylesheet" ) 
                        {
                            $linkpath=$link->getAttribute('href');
                        }

                        $links = explode("/", $linkpath);
                        $linkName = end($links);
                      $path="";
                  for ($i=0;$i<(count($image)-1);$i++) 
                      {
                        $path .= $image[$i] . "/";
                        if(!file_exists('folder/'.$path))
                            {
                                mkdir('folder/'.$path, 0777, true);     //css folder created
                            }       
                      }

                            file_put_contents('folder/'.$path.$linkName,file_get_contents($url_path.$linkpath));    //download css
                        }
?>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top