how to check for dmoz directory listing for all the pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swetha
Forum Commoner
Posts: 88
Joined: Wed Sep 10, 2008 11:00 pm

how to check for dmoz directory listing for all the pages

Post by swetha »

we have a code for checking of directory submission for dmoz(http://www.dmoz.org).
The code works for the first page fine,but i need to check for the listing of the categories in all the pages.

Code: Select all

 
<?php
            if (isset($_POST['submit']))
                {
 
                $sitename=$_POST['sitename'];
                //$sitename = $_POST['txtwebsite'];
                //To Strip upto http//www. from the url  
                $withwww = strstr($sitename,"www.");
                //returns:www.aaat.com;
                if(strstr($sitename,"www."))
                {
                    //returns:aaat.com
                    $sitename = substr($withwww,4);
                }
                //$strurl=formatURL($temp);
                $strurl='http://search.dmoz.org/cgi-bin/search?search='.$sitename;
                //echo 'value of strurl:' .$strurl . "<br>";
                $fp=@fopen($strurl,"r");
                if($fp)
                {
                        while (!feof($fp))
                        {
                        $buffer .= fgets($fp, 128);
                        }
                        
                        //echo "strpos:" . strpos($buffer, "Try your search on") . "<br>";
                        if(!strpos($buffer, "Try your search on")) 
                        {
                            $found = "Yes";
                        }    
                        else 
                        {
                            $found = "No";
                        }
                        fclose ($fp);
                
                        //echo "value of found:". $found;
                    echo "<table><tr><td><strong>Dmoz Listing :</strong> $found</td></tr>";
                    //If listed in demoz show this else hide 
                    if($found == "Yes"){
                
                    
                    //To get the total count from (1-2 of 2)
                    $delimeterLeft = "(";
                    $delimeterRight = ")";
                    $posLeft  = strpos($buffer,$delimeterLeft)+1;
                    $posRight = strpos($buffer,$delimeterRight,$posLeft+1);
                    $totalstring = substr($buffer,$posLeft,$posRight-$posLeft);
                    list($many,$total)=split("of",$totalstring);
            
                    //To get the title and description and category in dmoz
                    $Totlist = preg_match_all("/(<ol.*>)(\w.*)(<\/ol>)/ismU",$buffer,$patterns);
                    
                    //For category listing 
                    $category = array();
                    array_push($category,$patterns[0][0]);
                    $catlist = strip_tags($category[0]);
                    $cat = explode(")",$catlist);
 
                    //For title and description
                    $res = array();
                    array_push($res,$patterns[0][1]);
                    $getall = explode(")",$patterns[0][1]);
                    
                    echo "<tr><td><img src='images/category.gif'>&nbsp;&nbsp;Title&nbsp;&nbsp;<img src='images/desc.gif'>Description&nbsp;&nbsp;<img src='images/title.gif'>&nbsp;&nbsp;Category</td></tr>";
                    //Split the url to get the sitename only
                    //http://search.dmoz.org/cgi-bin/search?search=test.com
                    //To get test.com only
                    list($url,$site) = split("=",$strurl);
                    
                    //Listing all in a row
                    //assigning scrollbar for output
                    
                    echo "<tr><td><div style=\"overflow:scroll; height:250px; width:510px;\">";
                    for($i=0;$i<$total;$i++)
                    {
                    if($i%2 == 0)
                    {
                        $color = "#DADADA";                 
                    }
                    else 
                    {
                        $color = "#FFFFFF"; 
                    }
                        $totalcat[$i] = explode("(",$cat[$i]);            //Category
                        $gettitdesc[$i] = explode("--",$getall[$i]);         
                        $splittitdesc[$i] = explode("-",$gettitdesc[$i][0]);
                        //If url comes with hypen like we-buy-houses.com while spliting this with - lead to error
                        //we cannot get title and description
                        //it will split as we , buy , houses and description as arrays
                        //So we strip html tags
                        $titledesc[$i] = strip_tags($gettitdesc[$i][0]);
                        list($dmoztitle,$dmozdesc) = split("-",$titledesc[$i]);
                            
                        //To avoid duplicate sites from listing
                        //IF aaat is given as site,will list urls like soandso.com/aaat/index.htm
                        //To avoid this, we use the if condition
                        if(strpos($gettitdesc[$i][0],$site))
                        {
                        //Dmoz Title
                        ?>
                            
                        <table  bgcolor="<?=$color?>">
                        <tr>
                        <td><font color='red'><?php  echo $dmoztitle;?></font></td>
                        </tr>
            
                        <tr>
                        <td><font color='blue'><?php echo $dmozdesc;?></font></td>
                        </tr>
            
                        <tr>
                        <td><font color='green'><?php print_r($totalcat[$i][0]);?></font></td>
                        </tr>
                        </table>
                        <?php
                        } //End if strpos
                      }//End for
                      echo "</td></tr></div>"
                    }//End if-found
                  }//End if(fp)     
               }//End if-isset    
             ?>   
 
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: how to check for dmoz directory listing for all the pages

Post by josh »

Why not use xpath?
Post Reply