Just tried it again and you're right it does create the epub file correctly just crashes out when finished by the look of it. I see what you mean about the formatting improvements, it's only a little thing but it does look better. I feel really stupid for not trying that now, I honestly don't know why I didn't. I suppose it was one of those cases of a blanked mind cause I've never used php before so I didn't even try any of the simple troubleshooting steps first, DOH.
Thanks for the tip about the output name I only read completed stories so that will be the best option for me. I've actually tried two versions of your epub.codec.php just in case that was the problem and to be completely honest i now have no idea which one I'm actually using but I'm not gonna touch it while it works.
Thanks for all your help it really is appreciated.