Paying for Answers

09 Mar 2007

I've been subscribed to the general PHP mailing list for many years. I used to be very active, answering hundreds of questions a month, but lately my participation has dropped. While scanning through my backlog of email earlier, one subject caught my eye:

$35 to the first person who can do this XML-parsing PHP script

I was curious enough to open the email and read further:

I'll send $35 to someone via Paypal who can create a PHP script that will do the following:

  1. Read XML data from a URL (
  2. Loop through all XML results and print to the screen the eventname and eventnextoccurrencedate (just the date) values.

To my surprise, no one had responded, so I decided to quickly provide a solution. I wasn't expecting to be paid, but I couldn't resist calling someone's bluff, especially since I knew SimpleXML would make this a 5-minute problem, regardless of what the XML document looked like. A few minutes later, I responded:

  1. <table>
  2.     <tr><th>Name</th><th>Date</th></tr>
  3. <?php
  5. $xml = simplexml_load_file('');
  7. foreach ($xml->source->result as $f) {
  8.     $name = '?';
  9.     $date = '?';
  11.     foreach ($f as $value) {
  12.         if ($value['n'] == 'eventname') {
  13.             $name = $value;
  14.         } elseif ($value['n'] == 'eventnextoccurrencedate') {
  15.             $date = date('D, d M Y H:i:s', strtotime($value));
  16.         }
  17.     }
  19.     echo " <tr><td>{$name}</td><td>{$date}</td></tr>\n";
  20. }
  22. ?>
  23. </table>

I don't bring this up to extol the virtues of SimpleXML. I'm more interested in exploring the idea of paying for answers.

Paying for answers isn't a new idea (even Google has experimented with it), but I can't think of a success story. Can you?