Wordpress Tags grabber

Discussion in 'General Programming Chat' started by Boxic, Jan 27, 2009.

  1. Boxic

    Boxic Newbie

    Joined:
    Dec 20, 2008
    Messages:
    7
    Likes Received:
    3
    Not sure what you could use this for, i used it just to bloat some pages out with keywords.

    It grabs what wordpress . com considers to be "hot topics" via h t t p : / / wordpress . com /tags/

    (Sorry i can not post links yet)

    Code:
    <?
    
    $wp_page = file_get_contents(trim("h t t p : / / w ordpress . com/tags/"));
    
    $regex = '#<p class="heatmap"[^>]*>(.*?)</p[^>]*>#is';
    preg_match_all($regex,$wp_page,$wp_page_1);
    echo "<pre>";
    //var_dump( $wp_page_1 );
    echo "</pre>";
    
    $regex = '#(<a href=\'(.*?)>)(.*?)(</a[^>]*>)#is';
    preg_match_all($regex,$wp_page_1[0][0],$wp_page_2);
    echo "<pre>";
    //var_dump( $wp_page_2[3] );
    echo "</pre>";
    
    foreach ($wp_page_2[3] as $tag)
    {
            $font_size = rand(10, 25) . "." . rand(1, 99);
            $wp_tag_cloud .= "<a href='javascript:cloudsearch(\"". $tag ."\");' style='font-size: ". $font_size . "px;' title='". $tag ."'>".$tag."</a> \n";
    }
    echo $wp_tag_cloud;
    $fp = fopen('tagcloud.txt', 'w');
    fwrite($fp, $wp_tag_cloud);
    fclose($fp);
    ?>
    
    I just used rand() to make my own font sizes just to make it look a bit "better" for what i needed, but you can do what you like with it $tag within the foreach loop is all you need to work with. This example dumps my fake cloudsearch url to tagcloud.txt