I roleplay Second Life, and got the crazy idea of making a "mimir" - an item made semi-famous in AD&D as something that could give advice, which wandering the realms. Only, my version would just, at off times (via a command to the object), spit up a word definition. Basically, this means, while in world, I pick a work out of the stuff someone else said, use a command to tell the mimir object to ask what the definition is, then it's script makes a web request, retrieving the result, and, bingo, it can "speak" the definition so everyone hears it.
No, the original version works, sort of, but relying on pulling the first line out of an excerpt from Wikipedia, by telling it to send back "only" the excerpt, and in json. Which.. half the time doesn't give you any data, and the other half returns some reference to different pages, but, actual dictionaries do not generate json responses, which can be conveniently pulled apart, to get the result. So.. I hunted for an online dictionary that gave a "clean" page, which could be scraped, in the theory that this would be easier. Right... But, in principle it should be possible. Only.. I don't seem to be getting a page of data back at all. But then, I am hacking this together, with no clue what I am doing. So.. Here is what I came up with to "test" the process:
<?
if (isset($GET['word']))
{
$word=$GET['word'];
echo $word;
$data = file_get_contents('http://en.wiktionary.org/wiki/' . $word);
echo $data;
$regex = 'class="Latn headword".</ol>';
preg_match ($regex, $data, $match);
echo $match;
$regex = '<li>.</li>';
preg_match ($regex, $match, $def);
echo $match . ':' . $def;
}
else
echo 'no data';
?>
Supposedly, this should work. It should pull the html contents from wiktionary, find the first case of the class="Latn headword", then pull the contents of the "first" <li> section, which contains one of the definitions for the resulting word. Obviously, I need, later, to add code in to strip out html links it might throw at me, or spit out a "no data" when there is no definition available. But, even this simple test cases is failing - it doesn't deliver the html content from the page, so it can't search the contents for the stuff I am looking for.
Is there some other function I should be using? Am I doing someone completely wrong?
Ultimately, this should output the result, in a form that is seen by the object making the http request, and just repeated, without any additional hassle, unlike reading wikipedia, which turned out to give me data too large for the LSL script to handle, and forced me to do some more... complicated, things to get the data out. Its also why I am looking at having a php script do it, indirectly, rather than trying to hunt the data I need, inside the LSL Second Life scripting. :p