hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : byte string in php
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

byte string in php

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-28-2008, 03:18 PM
Adam Hallett Adam Hallett is offline
WHT Addict
 
Join Date: Aug 2001
Posts: 123

byte string in php


I'm creating a php script that uses Gnutella. I've parsed past the headers and now I need to process the descriptor id. The descriptor id is a 16-byte string uniquely identifying the descriptor on the network." How do I convert a byte string into a regular string?

-Adam

Reply With Quote


Sponsored Links
  #2  
Old 09-28-2008, 05:32 PM
ThatScriptGuy ThatScriptGuy is offline
Web Hosting Master
 
Join Date: Feb 2003
Location: AR
Posts: 2,370
I believe you're looking for this function

PHP has all sorts of multibyte string functions built right in.

http://us.php.net/mbstring

__________________
Kevin Cackler
Tech Daddies - A Conway, Arkansas based development company.
501-205-1512

Reply With Quote
  #3  
Old 09-28-2008, 06:16 PM
Adam Hallett Adam Hallett is offline
WHT Addict
 
Join Date: Aug 2001
Posts: 123
Do I need to use ord() with that function?

Btw, http://rfc-gnutella.sourceforge.net/...0_6-draft.html

Reply With Quote
Sponsored Links
  #4  
Old 09-28-2008, 09:49 PM
Adam Hallett Adam Hallett is offline
WHT Addict
 
Join Date: Aug 2001
Posts: 123
Here's the code:

Quote:
while ( ! feof($fp ) ) {
$buf .= fread($fp,1);
if ( strstr($buf, "\r\n\r\n") ) {
$split = split ("\r\n\r\n",$buf);
$data = $split[1];

var_dump($split);

while ( strlen($data) < 23) {
$data .= fread($fp,1);
}

break;
}
}
while(1){
$descrip = substr($data,0,15);
$ttl = ord($data[17]);
$hops = ord($data[18]);
$payload_len = substr($data,19, 22-19);

$plen = ord($payload_len);

$this->_log("hops: $hops; ttl: $ttl payload_len: $plen,$payload_len");

switch (ord($data[16])) {

case 0x00:
$this->_log('ping');
break;
case 0x01:
$this->_log('pong');
// $sin = fread($fp, $datasize);
break;
case 0x40:
$this->_log('push');
// $sin = fread($fp, $datasize);
break;
case 0x80:
$this->_log('query');
// $sin = fread($fp, $datasize);
break;
case 0x81;
$this->_log('queryhit');
// QueryResponseDataAvail($fp, $datasize);
break;
} // switch


fread($fp,$payload_len);
$data = '';
while ( strlen($data) < 23 ){
$data .= fread($fp,1);
}

}

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
CloudFlare Crashes After Juniper Edge Routers Fail Web Hosting News 2013-03-04 15:31:30
Will ICANN's New gTLD Application System Downtime Affect Web Hosts? Web Hosting News 2012-04-30 16:37:55
NGINX 1.2.0 Update of Web Server Improves HTTP Proxy Support Web Hosting News 2012-04-24 16:47:23
Web Hosts Add New Intel E5 Romley Servers to Boost Performance by 80 Percent Web Hosting News 2012-03-09 13:56:51
Oracle is the Latest Vendor to Apply Patch for Apache Killer Flaw Web Hosting News 2011-09-19 14:43:58


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?