. You can customize the replacements by changing the $text variable. It is a multi-line string. All comment lines begin with # There is a tab character between the string to replace and the replacement. Look further down for the HTML creation. You will want to replace the HTML to make it look the way you wish. **/ $text = " ### From Substitutions ### witneses these dudes I know allegedly kinda probably new study tumblr post rebuild avenge space spaaace google glass virtual boy smartphone pokedex electric atomic senator elf-lord car cat election eating contest congressional leaders river spirits homeland security homestar runner could not be reached for comment is guilty and everyone knows it ### From Substitutions 2 ### debate dance-off self driving uncontrollably swerving poll psychic reading candidate airbender drone dog vows to probably won't at large very large successfully suddenly expands physically expands first-degree friggin' awful second-degree friggin' awful third-degree friggin' awful an unknown number like hundreds front runner blade runner global spherical years minutes no indication lots of signs urged restraint by drunkenly egged on horsepower tons of horsemeat ### From Substitutions 3 ### gaffe magic spell ancient haunted star-studded blood-soaked remains to be seen will never be known silver bullet way to kill werewolves subway system tunnels I found surprising surprising (but not to me) war of words interplanetary war tension sexual tension cautiously optimistic delusional doctor who the big bang theory win votes find pokemon behind the headlines beyond the grave email poem facebook post poem tweet poem latest final facebook ceo this guy disrupt destroy meeting menage a trois scientists Channing Tatum and his friends you won't believe I'm really sad about "; $lines = explode("\n", trim($text)); $find = array(); $replace = array(); foreach($lines as $line) { $line = trim($line); if($line == '') continue; if($line{0} == '#') continue; $a = explode("\t", $line); if(sizeof($a) == 2 && $a[0] != '') { $find[] = '/\b'.$a[0].'\b/i'; $replace[] = $a[1]; } } exec("lynx -dump http://news.google.com", $lines); $news = array(); foreach($lines as $line) { $line = trim($line); if(preg_match("/^\[([0-9]+)\](.*)$/", $line, $matches)) { if(sizeof($matches) == 3) $news[$matches[1]] = array('title'=>trim($matches[2])); } elseif(preg_match("/^([0-9]+)\.(.*$)/", $line, $matches)) { if(sizeof($matches) == 3 && isset($news[$matches[1]])) $news[$matches[1]]['url'] = trim($matches[2]); } } foreach($news as $i=>$a) { $title = fix_headline($a['title']); if(strtolower($title) == strtolower($a['title'])) unset($news[$i]); else $news[$i]['new'] = $title; } /** Replace the HTML here to customize the resulting HTML page. **/ $html = ''; $html.= "

News Substitutions

\n"; $html.= "

Substitutions make reading the news more fun:

\n"; if(sizeof($news)==0) $html.= "I'm sorry, but there is no interesting news today."; else { $html.= "\n"; } $html.= "

These substitutions (and this entire idea) comes from XKCD news substitutions\n"; $html.= "here,\n"; $html.= "here,\n"; $html.= "and here.\n"; $html.= "

\n"; $html.= "\n"; file_put_contents("news_substitutions.html",$html); function fix_headline($headline) { global $find, $replace; $headline = ucwords(preg_replace($find, $replace, $headline)); return preg_replace(array( '/\bA\b/', '/\bAn\b/', '/\bThe\b/', '/\bAnd\b/', '/\bBut\b/', '/\bOr\b/', '/\bFor\b/', '/\bNor\b/', '/\bOn\b/', '/\bAt\b/', '/\bTo\b/', '/\bFrom\b/', '/\bBy\b/', '/\bIs\b/', ), array( 'a', 'an', 'the', 'and', 'but', 'or', 'for', 'nor', 'on', 'at', 'to', 'from', 'by', 'is', ), $headline); } ?>