A
Anonymous
Guest
I thought I'd start a topic for people to talk about their current or recent projects (PHP or otherwise). Anybody doing anything interesting? Looking for feedback or just want to boast? Post it here.
------------------------------
My current project:
Currently I'm writing a PHP interface to the DAAP protocol, which is the protocol that Apple's iTunes uses to share and stream playlists
I'm not a Mac person at all, but it seemed like an interesting challenge. The DAAP protocol is built atop HTTP, so interfacing with the server is pretty simple, but making sense of the data that iTunes returns is quite a challenge. Fortunately, a number of people have already done most of the footwork for me (1, 2).
The big challenge has been learning how to deal with binary data in PHP. When you query iTunes, the response is in a binary format (no human-readable XML or anything, here). I just started working on this tonight, about six hours ago, and with the help of the protocol documentation, I've been able to write a function (recursive, no less) that takes the binary data returned by iTunes and turn it into an array in PHP. My eventual goal is to make an OOP interface to the DAAP server., and then use that to build some sort of web-based DAAP-browsing app. We'll see how far I get.
If anybody's really interested in how this project is going, send me a PM (or post below) and I'd be happy to discuss it and show you what I've got, though at this point I don't want to turn it into a team project -- I'm just tinkering now. But I have come up with a couple of functions that might be helpful for other projects.
The first should be easy, but it took me a long time to figure out. It's a function to take a binary string (not a string of 1s and 0s, but an actual string of binary data -- for the former, just use bindec()) and return its integer value:
The second has come in very handy for dealing with binary data. It prints the hexadecimal representation of a string, nicely formatted into rows ($width, default 16 bytes/row) and columns ($break, default 4 bytes/col). There's also an option ($return_text = 1) to format the plaintext representation, which is useful if you want a side-by-side view (dont forget to use <pre></pre> to preserve formatting). Certain characters in the plaintext view can foul up the layout, but other than that it's a very useful tool:
Here's an example of its output, from iTunes' /server-info command:
Okay, so what's everybody else working on?
------------------------------
My current project:
Currently I'm writing a PHP interface to the DAAP protocol, which is the protocol that Apple's iTunes uses to share and stream playlists
I'm not a Mac person at all, but it seemed like an interesting challenge. The DAAP protocol is built atop HTTP, so interfacing with the server is pretty simple, but making sense of the data that iTunes returns is quite a challenge. Fortunately, a number of people have already done most of the footwork for me (1, 2).
The big challenge has been learning how to deal with binary data in PHP. When you query iTunes, the response is in a binary format (no human-readable XML or anything, here). I just started working on this tonight, about six hours ago, and with the help of the protocol documentation, I've been able to write a function (recursive, no less) that takes the binary data returned by iTunes and turn it into an array in PHP. My eventual goal is to make an OOP interface to the DAAP server., and then use that to build some sort of web-based DAAP-browsing app. We'll see how far I get.
If anybody's really interested in how this project is going, send me a PM (or post below) and I'd be happy to discuss it and show you what I've got, though at this point I don't want to turn it into a team project -- I'm just tinkering now. But I have come up with a couple of functions that might be helpful for other projects.
The first should be easy, but it took me a long time to figure out. It's a function to take a binary string (not a string of 1s and 0s, but an actual string of binary data -- for the former, just use bindec()) and return its integer value:
Code:
<?php
// convert a binary string to an int
function bin2int($bin) {
return hexdec(bin2hex($bin));
}
?>
The second has come in very handy for dealing with binary data. It prints the hexadecimal representation of a string, nicely formatted into rows ($width, default 16 bytes/row) and columns ($break, default 4 bytes/col). There's also an option ($return_text = 1) to format the plaintext representation, which is useful if you want a side-by-side view (dont forget to use <pre></pre> to preserve formatting). Certain characters in the plaintext view can foul up the layout, but other than that it's a very useful tool:
Code:
<?php
function bin_dump($string, $width = 16, $break = 4, $return_text = 0) {
$line_count = 0;
$section_count = 0;
$hex = '';
$text = '';
for($i = 0; $i < strlen($string); $i++) {
$line_count++;
$section_count++;
$hex .= str_pad(strtoupper(dechex(ord($string{$i}))), 2, '0', STR_PAD_LEFT);
$text .= $string{$i};
if($line_count == $width) {
$hex .= "\n";
$text .= "\n";
$line_count = 0;
$section_count = 0;
} elseif($section_count == $break) {
$hex .= ' ';
$text .= ' ';
$section_count = 0;
} else {
$hex .= ' ';
}
}
if($return_text > 0) {
return $text;
} else {
return $hex;
}
}
?>
Here's an example of its output, from iTunes' /server-info command:
Code:
6D 73 72 76 00 00 00 A7 6D 73 74 74 00 00 00 04
00 00 00 C8 6D 70 72 6F 00 00 00 04 00 02 00 00
61 70 72 6F 00 00 00 04 00 02 00 00 6D 69 6E 6D
00 00 00 12 41 67 69 74 61 74 65 64 20 4C 75 6E
63 68 6C 61 64 79 6D 73 6C 72 00 00 00 01 00 6D
73 74 6D 00 00 00 04 00 00 07 08 6D 73 61 6C 00
00 00 01 00 6D 73 75 70 00 00 00 01 00 6D 73 70
69 00 00 00 01 00 6D 73 65 78 00 00 00 01 00 6D
73 62 72 00 00 00 01 00 6D 73 71 79 00 00 00 01
00 6D 73 69 78 00 00 00 01 00 6D 73 72 73 00 00
00 01 00 6D 73 64 63 00 00 00 04 00 00 00 01
Okay, so what's everybody else working on?