We used chunk_split() to split up spots by a certain amount of characters, but if a space was at the end of that spot, we would create invalid XML.

Fixed by using our own safe_chunk() function which tries to avoid this kind of situation.

Reported by pkoopmanpk #1953