Archive for the 'PHP' Category

What is Notice: unserialize() [function.unserialize]: Error at offset then?

Problem: While doing some Shopp Plugin support work earlier, one customer was getting this error… Notice: unserialize() [function.unserialize]: Error at offset 111 of 118 bytes in /home/maxwell4/public_html/main/wp-content/plugins/shopp/core/model/Settings.php on line 228 …she had done a ‘find and replace’ in a SQL DB dump to change her domain name, boogered it up accidentally, and needed an explanation. [...]

Set date.timezone in PHP without using php.ini

Problem: I needed to set default timezone for a site to get Zen Cart installed. The usual way would be to call date_default_timezone_set from a globally included script, or to use the date.timezone option in a php.ini file. The problem is that I don’t have access to the php.ini file and there is no script that [...]

Convert eregi_replace to preg_replace in old class.phpmailer.php scripts

Problem: I have lots of legacy php code on old sites that uses eregi_replace to format up an HTML email body. As eregi_replace is now depreciated it can be replaced with preg_replace. This is tricky sometimes because the formatting is quite different. Fix: Here’s a common line from class.phpmailer.php scripts: $emailBody = eregi_replace("[\]",”,$emailBody); To convert that you’ll need to do this: [...]

Swap days and months in PHP – quick and dirty MM/DD/YY to DD/MM/YY

Problem I have a ton of date strings in the stupid US style dd/mm/yy format. i.e. 12/24/09 being 24th September 2009. I need to convert them to the UK style dd/mm/yy. Solution 1 As a string in PHP is really just an array of characters, the simplest fix was to address the individual number characters [...]