Add Links to a Block of Text Automatically

Auto-Linker uses the Yahoo! API to add relevant links to keywords in any text.

Isn’t the task of inserting links into web pages mundane? The Yahoo! Auto-Linker solves this problem by automatically substituting keywords in anytext with hyperlinks to top Yahoo! searches for that keyword. The result of this hack can be useful and inspiring, bizarre, or just plain amusing. The Auto-Linker accepts a bit of text via a web page form like the one shown in Figure 5-23 and returns the same block of text with hyperlinks inserted.

The same web page, now illustrated with yReplacer

Figure 5-22. The same web page, now illustrated with yReplacer

The Auto-Linker text-entry form

Figure 5-23. The Auto-Linker text-entry form

At http://blog.outer-court.com/yahoo/autolinker.php5, you can play with a working version of Auto-Linker and see how it works in detail. Once you’re comfortable with it, you can build your own version with the code in this hack.

The Auto-Linker makes use of two Yahoo API services when it auto-links a given text. First, it finds the significant phrases within the text using Yahoo’s Term Extraction (http://developer.yahoo.net/content/V1/termExtraction.html).

Second, it uses the Yahoo! Web Search (http://developer.yahoo.net/web/V1/webSearch.html) to find the top web page for this phrase. All that’s left to do is add the corresponding ...

Get Yahoo! Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.