I'm working on a page that displays the first search result in Google.
So let's say you visit www.mydomain.com/?q=John+Doe you are redirected to www.google.com/?q=John+Doe.
This is already working fine, but here's the question:

I would like it to redirect to the first result, instead of the results page.
So if /?q=John+Doe points to www.johndoe.com, redirect to there.

How can I isolate and interpret that first result?
Returning the URL of the first result is what I'm looking for.

Thanks!

PS. I'm working in PHP and JavaScript/AJAX.