Jump to content

Recommended Posts

Hi, I have a funny string that I'm pulling from a database, and I need to take a specific element out of it to try to organize some message statistics. This is what it looks like:

 

a:1:{s:2:"cc";a:1:{i:3;s:7:"Name";}}

 

I need to pull the name out of the strong. Luckily, all of the strings only have 4 characters at the end, which makes it easy to remove, but the numbers can change in the first part, making that difficult to do as well. To further complicate it, sometimes the messages may go to multiple users, such as:

 

a:1:{s:2:"cc";a:3:{i:1;s:6:"Name1";i:5;s:6:"Name2";i:3;s:7:"Name3";}}

 

Subsequently, the trimming of 4 at the end seems a little uglier. The one thing I can tell from the syntax is that I can ignore the first 2 quotes. The third quote is the start of a name, the fourth quote the end of one. If there are any more, it continues that pattern. Anyone know how I can parse this string nicer?

 

Thanks in advance!

It's created in vBulletin (no idea where in the code it's so large), and this is a list of recipients of those who receive PMs. I'm trying to put together a strict to track stats (most sent out, most received, etc), but don't know of any functions that may be able to replace up to a certain character and such.

You really don't want to be playing around with the serialized array itself. Unserialize it first.

 

Assuming you have your string stored in $s, what does the following look like, and how would you like it read?

 

<?php

  echo "<pre>";
  print_r(unserialize($s));
  echo "</pre>";

?>

It's created in vBulletin (no idea where in the code it's so large)

 

Run some searches against the code. Try things like "serialize" or "PM". If you're on a Unix box cd to the VBulletin root and run find . -type f -exec egrep '(serialize|PM)' {} /dev/null \;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.