Skip to content

Instantly share code, notes, and snippets.

@astf-robot
Last active May 8, 2018 10:36
Show Gist options
  • Save astf-robot/2b332daa479d714a192a to your computer and use it in GitHub Desktop.
Save astf-robot/2b332daa479d714a192a to your computer and use it in GitHub Desktop.
Synonyms
<?php
if ($argc < 2) {
echo "Usage ${argv[0]} WORD\n";
exit(1);
}
$html = file_get_contents('http://www.thesaurus.com/browse/' . $argv[1]);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$synonyms = $xpath->query('//a[@data-category]/span[@class="text"]');
foreach ($synonyms as $synonym) {
echo $synonym->textContent . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment