WARNING: Error at offset 761 of 5887 bytes Unserialize PHP string

Friday, 14. June 2013

If you have worked with serialize function in PHP to serialize objects in order to save them in database – and ofcourse if you are reading this post – you have once come across this error

WARNING: Error at offset 761 of 5887 bytes

It’s annoying and always gets me. The main reason for this problem is due to the fact that you have either empty variables in your serialized string or unwanted characters.

The simple solution will be to ensure your encode the string first before you save it to the database.. seems to work well for me (but of course test if for your needs and let us know if it worked for you!)

encode your serialized string with base64

$safeSerializedString = base64_encode(serialize($this->_arrayData));

decode your serialized encoded string with

 $_array_object = unserialize(base64_decode($_row["serialized_column"]));

Enjoy!

Find URLs in Text description With Regex PHP

Saturday, 20. October 2012

This little regex script gives you another simple way to fetch for all possible URLs embedded as simple text in a your rather large description text.

It’s flexible and you can add more filters appropriate for your requirement as you wish..

# take it to the test!
$matches = null;
$returnValue = preg_match_all('%(https://|http://|www)[a-zA-Z0-9\/#&-_\.]+%', $desc_variable, $matches);
# see what you got!
var_dump($matches);

Enjoy!

Remove Everything After Character Pattern Preg_Replace Regex expression

Monday, 23. July 2012

A little snippet that simply removes everything after a matched pattern using preg_replace regular expression.

Example

# remove everything after TEL: symbol
$address = "John Scott, Leeds, UK. TEL: 000111-234 345";
# new address
$new_address = preg_replace('/TEL:.*/i', '', $address, -1, $count);

Enjoy!

Manually Format Prices Using Number_Format

Thursday, 5. April 2012

If you have used round, floor etc while trying to format the prices display in Magento (or any other cart for that matter) but to undesired effect due to decimal points – a php number_format could be just the solution you are looking for!

It format the number nicely with ability to round and even change the decimal separator!

It also keeps the ending ‘0’ so you are sure your price display will be consistent across the pages.

Example:

number_format($_product->getPrice(),2); # 23.70

You can ready more Here

Use Curl With Magento and Zend Framework

Tuesday, 25. October 2011

Just a little snippet of curl implementation inside Magento for anyone interested.

try {
 
  $http = new Varien_Http_Adapter_Curl();
  $config = array('timeout' => 30); # Or whatever you like!

  ## You attach proxy with your custom implementation like this::
  if ($this->getUseProxy()) {
    $config['proxy'] = $this->getProxyHost(). ':' . $this->getProxyPort();
  }
 
  ## You can add ssl certificate with your custom implementation like this::
  if ($this->getUseCertAuthentication()) {
    $config['ssl_cert'] = $this->getApiCertificate();
  }
  $http->setConfig($config);
 
  ## make a POST call
  $http->write(Zend_Http_Client::POST, $this->getApiUrl(), '1.1', array(), $requestQuery);
 
  ## Get Response
  $response = $http->read();
 
} catch (Exception $e) {
 
  $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
  $this->_debug($debugData);
  throw $e;
}
 
# Close Call
$http->close();

PHP – Magento Jobs At Zone-Connect Leeds UK

Friday, 21. October 2011

– Are you excellent with PHP?

– Do you have any experience in E-Commerce and/or Magento platform?

– Do you enjoy working with PHP and other Web Development technologies, platforms or frameworks currently available?

– Are you looking for a job that will challenge you every day but also provide you with an opportunity to be creative?

– Can you work on your own, good at making decisions and quick at finding solutions when you hit the wall?

– Are you based in Leeds (or close range) area in UK?

– Are you looking for decent rewards for your hard work?

– Can you work for at least 3 days a week?

If you feel like you have the answers for these questions, please get in touch with us today.