lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP: Blogger Wrapper Regex
When you use Blogger's ATOM API to post entries to your blog, it will add a div wrapper to your content:

<div xmlns="http://www.w3.org/1999/xhtml">content of post</div>


Thus, if you post then retrieve an entry, you'll get this wrapper stuck arround it. If post and retrieve multiple times, you'll get multiple wrappers.

The following PHP code should get rid of any and all such wrappers, though it comes with no warranties:

while ( preg_match('%^<div xmlns="http://www\.w3\.org/1999/xhtml">(.*)?(</div>)$%is', trim($string), $_MATCH) )
{
$string = trim($_MATCH[1]);
}
$unwrapped_string = $string;


Note on regex expression: (.*)? successfully selects all up until the final closing div tag.

Mind the gap.

keywords: php, regex, blogger, atom