I'm working on a WordPress plugin that exports posts and associated data into a tab-seperated text format. It's almost finished, but I'm struggling to find the best method to re-process HTML into single strings.
I'm using a combination of preg_replace and htmlentities, but it's getting a little messy.
I'm sure there must be a preferred method for doing this, so I thought I would check with you? I can't find anything suitable on Google.
There's no single sure fire way but some simple regex would do the trick:
// remove convert newlines and multiple spaces into 1 space
$html = preg_replace("/\s+|
+|/", ' ', $html);
Have you considered base64 encoding?
$foo = base64_encode($data);