Full-stack web applications developer

Welcome to my blog

As I discover new things in my field and solve troublesome problems, I will attempt to document my finds here.

Solution to some PHP unserialize offset errors

On September 17, 2018, by Arthur Pemberton, 0 Comments

I was getting PHP `unseralize` errors when working with some WordPress option values.

PHP Notice: unserialize(): Error at offset 4854 of 24578 bytes

One of the comments in the `unserialize` documentation was suggested matching all string values, and correct the string length. Working with that, and checking the area of breakage (byte 4854) I found a string which was declared as 64 characters, but serialized as 61. So I went ahead and adapted the 6 year snippet to work on PHP 7.1.


function fix_serialized_string_lengths($matches) {
	if ( strlen( $matches[2] ) == (int)$matches[1] ) return $matches[0];

	$idx = strpos( $matches[0], ':', 2 );

	return 's:' . strlen( $matches[2] ) . substr( $matches[0], $idx );

$arr = @unserialize( $val );

if ( $arr === FALSE ) {
	$val = preg_replace_callback(

	$arr = unserialize( $val );

Changing the “Archive Title” used by WordPress

On July 21, 2015, by Arthur Pemberton, 0 Comments

If you are using an SEO plug-in with WordPress, you may have changed the <title> of one or more of your archives pages. However, the theme you are using is probably making use of the get_the_archive_title() WordPress function to get the title that is used in, for example, the <h1>.
Read More