Hartley Posted August 5, 2007 Share Posted August 5, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/ Share on other sites More sharing options...
trq Posted August 5, 2007 Share Posted August 5, 2007 Is this string a serialized array or something? How is this string created? Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-316234 Share on other sites More sharing options...
Hartley Posted August 5, 2007 Author Share Posted August 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-316244 Share on other sites More sharing options...
trq Posted August 5, 2007 Share Posted August 5, 2007 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-316245 Share on other sites More sharing options...
Hartley Posted August 6, 2007 Author Share Posted August 6, 2007 The :'s give me a parse error ;( Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-316323 Share on other sites More sharing options...
effigy Posted August 6, 2007 Share Posted August 6, 2007 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 \; Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-316740 Share on other sites More sharing options...
sasa Posted August 6, 2007 Share Posted August 6, 2007 a:1:{s:2:"cc";a:1:{i:3;s:7:"Name";}} is serialized array but in the end string "Name" is 4 characters long change s:7:"Name"; to s:4:"Name"; and try thorpe's code Quote Link to comment https://forums.phpfreaks.com/topic/63459-remove-characters-up-to-specific-character/#findComment-317071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.