Don't bother about batman's advice about stristr - it's wrong.
Your original code looks okay to me, except that getenv() might not be available in some circumstances: you could use $_SERVER['HTTP_USER_AGENT'] instead, though.
To test ... if you've got a client you can change the user-agent header on, you could change it to contain the string "Googlebot" and try it. Or you could change the string you're looking for to something that appears in your usual browser's User-Agent string; then hit the page and see if the extra meta tags appear in the returned page.
As for whether it will actually work ... that's kind of up to Google's Googlebot 🙂