Can someone help comment this 60 line script, so I can learn :)

Discussion in 'Programming' started by mudanoman, Sep 23, 2007.

  1. #1
    I am trying to learn some php and wanted to start understanding this script: http://www.sandaru1.com/2007/07/04/how-to-find-free-mp3-using-google/

       1. <?  
       2.     $stderr = fopen('php://stderr', 'w');  
       3.     set_time_limit(0);  
       4.     error_reporting(0);  
       5.   
       6.     $urls[] = "http://www.mcgees.org/mp3/pearl_jam/";  
       7.     $urls[] = "http://www.xieish.net/Collective%20Soul/";  
       8.     $urls[] = "http://www.asilentflute.com/mp3/";  
       9.     $urls[] = "http://www.semret.org/music/";  
      10.     $urls[] = "http://www.koreangirlssuck.com/emotion/mp3/";  
      11.     $urls[] = "http://www.vrees.net/mp3/";  
      12.     $urls[] = "http://www.webpiri.net/Mp3/";  
      13.     $urls[] = "http://pierre33200.free.fr/Music/";  
      14.   
      15.     $done = array();  
      16.   
      17.     for($i=0;$i<count($urls);$i++) {  
      18.         $url = $urls[$i];  
      19.         $done[strtolower($url)] = true;  
      20.         $temp = parse_url($url);  
      21.         $path = pathinfo($temp['path']);  
      22.         $domain = $temp['host'];  
      23.   
      24.         if ($path['extension']!="") {  
      25.             if (strtolower($path['extension'])=="mp3"  
      26.                 || strtolower($path['extension'])=="wma") {  
      27.                 echo $url."n";  
      28.                 continue;  
      29.             } else {  
      30.                 fwrite($stderr,"Escaping $url : Not mp3n");  
      31.                 continue;  
      32.             }  
      33.         }  
      34.   
      35.         fwrite($stderr,"Proccessing $urln");  
      36.   
      37.         $html = file_get_contents($url);  
      38.   
      39.         $direct = preg_match("/index of/i",$html);  
      40.         if ($direct==false) {  
      41.             fwrite($stderr,"Error : Not a directy indexn");  
      42.             continue;  
      43.         }  
      44.   
      45.         $count = preg_match_all("/<a href="(.*?)">.*?</a>/i",  
      46.                 $html,$matches);  
      47.         foreach ($matches[1] as $match) {  
      48.             // Ignore the pages link to same url  
      49.             if ($match[0] == "?")  
      50.                 continue;  
      51.             if (substr($match,0,7)=="http://")  
      52.                 $cur = $match;  
      53.             else if ($match[0] == "/")  
      54.                 $cur = "http://".$domain.$match;  
      55.             else  
      56.                 $cur = $url.$match;  
      57.             if (!isset($done[strtolower($cur)]))  
      58.                 $urls[]=$cur;  
      59.         }  
      60.     }  
      61.     fclose($stderr);  
      62. ?>  
    PHP:
    Thanks for your time!
     
    mudanoman, Sep 23, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    There are syntax errors in the script... are you sure it does even work?

    And do you have ANY knowledge about PHP? Because commenting won't help much if you have no idea at all. And commenting 60 lines just for fun is nothing I'm too interested in, to be honest.

    Or are there just a few specific parts that you need help with?
     
    nico_swd, Sep 23, 2007 IP