I was in class and we were finishing up so I couldn't elaborate:
you'll want to use socket functions to create a connection to the IRC server, then send raw IRC commands to join the channel or grab the topic (I don't know if /TOPIC is supported universally or not) but then you'd parse the raw buffer output for "topic on #channel is:" and strip from there out to the end character (possibly a Set by: statement or something) and then return that into a local variable and close your socket.
you'll want to use fsockopen, fwrite/fread, and fclose for the socket functionality. good luck! post any questions back here - I've written IRC bots in PHP before with full functionality, albeit a long time ago. 😉