PDA

View Full Version : Extracting Custom Calendar Fields from Database in PHP


AndyCooper
01-06-2009, 08:17 AM
Hi

I have some custom fields in my vbulletin calendar which I'd like to show on a non-vb page. Since the all the custom field information is held in a long string, the only way I can think of extracting, in the case of the example below is by using strpos and substr.

a:2:{i:1;s:19:"Birmingham, England";i:2;s:5:"88248";}

There has to be an easier way extracting the two items in quotes in the above string as two different variables instead of using something like:

$location = substr($row_Events['customfields'], strpos($row_Events['customfields'],"\"")+1, strpos($row_Events['customfields'],"\"", strpos($row_Events['customfields'],"\"")+1)-strpos($row_Events['customfields'],"\"")-1);

I'm open to any suggestions.

Thanks
Andy.

Dismounted
01-06-2009, 08:59 AM
The string is actually a serialized array. You can "reform" the array using the unserialize() function.

AndyCooper
01-06-2009, 09:22 AM
Superb, thanks!

$customfields = unserialize($row_Events['customfields']);
$location = $customfields[1];

That did the trick.

Andy