O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #24. Create Link Graphs

Use the font size of links to express the importance of certain terms.

Flikr (http://flikr.com/) is a site that allows users to upload images, and then tag those images with single-word terms. You can come back later and search the Flikr database using those terms, and you can see a link graph [Hack #91] that shows the most-used terms in a font larger than that used for the less frequently used terms.

In this hack, I show you how to create a link graph by analyzing an article from the Cable News Network web site (http://cnn.com/) for keywords. The words are counted, and the font size of each word is scaled relative to the number of counts.

The Code

Save the code in Example 3-19 as linkgraph.php.

Example 3-19. Link graph code

<?php $wordcounts = array(); $words = split( " ", "CNN number Americans disapproving President Bush job perance risen highest level presidency according CNN USA Today Gallup poll released Monday According poll percent respondents disapproved Bush performance compared percent approved margerror plus minus percentage points percent figure highest disapproval rating recorded CNN USA Today Gallup poll Bush president January approval percentage percent matches low point late March point gap between those disapproved approved largest recorded during Bush tenure As Bush prepares address nation Tuesday defend Iraq policy just percent those responding poll approved handling war percent disapproved Full story approval rating Iraq unchanged poll ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required