Hello to all,

I am not sure if this is even possible, but if it does I would gratefully appreciate the methods to implement this please.

We accept applications which require action to be taken (I won't go into the boring details) but part of it involves us looking up a provided word to see if it's bad or not. To do this, we use http://urbandictionary.com/ and google's "define:word" to see what it is

This method works fine, but purely as a time saving measure, I wondered if I could get PHP to contact both sites, and give the first definition it presents which I can display on the page?

The "word" we check is basically $row['word']

Basically, the simplest way of putting what I want to try and achieve is for the $row['word'] (whatever that may be) to be defined on both UrbanDictionary.com and Google's "define:word" (where you type that in the search field and it comes up their definitions)

Then for PHP to display those like:

UrbanDictionary: definition
Google Defintion: definition

And as mentioed on my first post, if there's no definition to state that, or if the site isn't contactable, a message about that

The reason I said the 'first' definition from both is because I know there'll likely be lots of each, and we just need the first (which seems to be the most accurate)

Any help appreciated, thank you.

    It could be done by using [man]cURL[/man] (or [man]file_get_contents[/man] if allow_url_fopen is enabled) to get the HTML text from those sites. Then you would have to do some "screen scraping" to grab the text of interest from those results. This would probably require some pattern-matching, perhaps via [man]preg_match[/man] and its related functions. The downside is that any changes to the format/structure of those pages may break your script until you modify it to catch up with those changes.

      And then you also have to consider the two sites' TOS/AUP to see if they allow automated requests to utilize their services.

        And if they do, see if they provide interfaces intended for automated use. Those would be easier for a machine (like your program) to read.

          Hi guys, thanksf or your replies 🙂

          Indeed, the API seems much more sensible for the reasons you mentioned, thanks for that...

          I visited UrbanDictionary and saw they do an API, so I've registered with them and got a key.

          From:
          http://wiki.urbandictionary.com/index.php/PHP

          I've used:

          <?
             define('KEY', 'your key here');
          
             $soap = new SoapClient('http://api.urbandictionary.com/soap?wsdl');
          
             try {
                $result = $soap->lookup(KEY, 'hello');
             }
             catch (SoapFault $se) {
                print $se->faultstring;
             }
          
             if ($result)
                print_r($result);
          ?>

          But when I load that (after putting my key in), it just dies, no errors or anything.

          Can you see anything else I should be doing?

          Also, as I mentioned on my first post, I really just wanted the first result to be shown, like "Urban Dictionary: definitionhere"

          Any ideas? 🙂

          Edit: just to include, I am running PHP5 ... Powered by PHP 5.1.6 (Apache/2.2.6 (Fedora))

            Try changing '<?' to '<?php' since short_tags are deprecated and most likely disabled.

              Hi there

              Changed that, unfortunately, still not working 🙁

              I'll try my error_reporting

              Edit: even with that, nothing :X

                Write a Reply...