0

I have a small problem with my code..I accessed the src value in the script tag to get the content of the JavaScript page that is found at the server side..It is ok as i get what i wanted but the problem is that i am getting the html code also..I dont want the html code. Here below is what i have done..Please help?

     <?php
    //simple_html_dom.php caters for malformed html
    include('simple_html_dom.php');  
    $html = new simple_html_dom();  

    //load the All code file 
    $html->load_file("test.txt");

    $file = fopen("externalScript.txt","w");

    $Script=$html->find("script");

    $temp="";
    $url="http://www.xyz.com";
    foreach($Script AS $Spt){
        $src=$Spt->src;
        //check if the script src has "http://" prefix
        if(strpos($src,'http://')!==0){
            $src=$url."/".$src;
        }
        $get_script=file_get_contents($src);

        $temp.=$get_script.PHP_EOL; 
    }
    fwrite($file,($temp));
    fclose($file);
?>
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Johnson Smith
  • 55
  • 1
  • 1
  • 7
  • have you tried hitting your `src`es manually in a browser? Just because they're listed in a page's source doesn't mean they actually represent real code. stale sites have stale html... – Marc B Oct 24 '13 at 19:25
  • am not understanding what u r trying to say..Can yu please explain this to me – Johnson Smith Oct 24 '13 at 19:39
  • if i place the src without the www.xyz.com it will not work,but with www.xyz.com/src it work – Johnson Smith Oct 24 '13 at 19:42
  • what do you expect? `file_get_contents('foo.js')` is a request to load a LOCAL file from YOUR server's drive. `file_get_contents('http://example.com/foo.js')` will do a full-blown HTTP request to the specific url and fetch the file. – Marc B Oct 24 '13 at 19:43
  • i expect the file_get_contents('http://www.example.com/foo.js')...this part works for me but i also get an html part and i want only the external script – Johnson Smith Oct 24 '13 at 19:46

0 Answers0