This will be incredibly difficult. You'd probably have to write you're own HTML renderer. At the very least you would need a browser on the server. It might be possible with a custom C or Java program working with your PHP script.
However you do it, it's almost certainly not worth it. 🙂