What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [PHP] Parsing the media string

[PHP] Parsing the media string
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. [PHP] Parsing the media string
Ok, this simply sucks. :P

I want to parse a string like:
code:
$psm = "\\0Music\\01\\0Nu op Q: {0} - {1}\\0When It All Falls Apart\\0Veronicas\\0\\0\\0";
to an array containing its elements, like:
code:
$match = array(4) {
  [0]=> string(5)
  "Music"
  [1]=> string(18)
  "Nu op Q: {0} - {1}"
  [2]=> string(23)
  "When It All Falls Apart"
  [3]=> string(9)
  "Veronicas"
}
using preg_match(). But now I have problems with the backslash... uh?!
This code fails:
code:
preg_match("/^\\0([a-zA-Z]+)\\01\\0(.*?)\\0(.*?)\\0(.*?)\\0(.*?)\\0(.*?)\\0(.*?)$/", $psm, $ico_match);
And while I tried to look for the fault, I found that this:
code:
preg_match("/0([a-zA-Z]+)/", $psm, $ico_match);
finds "Music", while this one:
code:
preg_match("/\\0([a-zA-Z]+)/", $psm, $ico_match);
fails. :-/

Any ideas? :P
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-23-2006 10:05 AM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [PHP] Parsing the media string
preg_match("/^\\\\0([a-zA-Z]+)\\\\01\\\\0(.*?)\\\\0(.*?)\\\\0(.*?)\\\\0(.*?)\\\\0(.*?)\\\\0(.*?)$/", $psm, $ico_match);

Note the quadruple backslashes.

Explanation: In JScript, the backslash is used to escpace certain special characters that are otherwise unprintable. To print a backslash therefore, you need to escape that too i.e. \\. So, for a double backslash, both need escaping, so \\\\.

This post was edited on 08-23-2006 at 11:00 AM by RaceProUK.
[Image: spartaafk.png]
08-23-2006 10:59 AM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [PHP] Parsing the media string
OMFG That's weird, but it worked! :P
* Matti notes: catching a backslash in PHP -> 4 backslashes

Thanks RP! ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-24-2006 07:45 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On