News:

Facebook killed the radio star. And by radio star, I mean the premise of distributed forums around the internet. And that got got by Instagram/SnapChat. And that got got by TikTok. Where the fuck is the internet we once knew?

Main Menu

[PHP] DebugOutput

Started by Joe, December 14, 2005, 07:48:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joe

I haven't seen this posted anywhere (not that I looked), so here it is! Ported by yours truely, from iago's BnetPacket.java.

  /* Creates a hex representation of a string */
  /* Ported from iago's JavaOp2 */
  function debugOutput($buffer) {
    $i = 0;
    $j = 0;
    $returnString = "";
    for($i = 0; $i < strlen($buffer); $i++) {
      if(($i != 0) && ($i % 16 == 0)) {
        $returnString = $returnString . "\t";
        for($j = $i - 16; $j < $i; $j++) {
        if(ord($buffer[$j]) < 0x20 || ord($buffer[$j]) > 0x7F)
          $returnString = $returnString . '.';
        else
          $returnString = $returnString . $buffer[$j];
        }
        // Add a linefeed after the string
        $returnString = $returnString . "\n";
      }
      $returnString = $returnString . bin2hex($buffer[$i]) . " ";
    }
    if($i != 0 && $i % 16 != 0) {
      for($j = 0; $j < ((16 - ($i % 16)) * 3); $j++) {
        $returnString = $returnString . " ";
      }
    }
    $returnString = $returnString . "\t";
    if($i > 0 && ($i % 16) == 0) {
      $j = $i - 16;
    } else {
      $j = ($i - ($i % 16));
    }
    for(; $i >= 0 && $j < $i; $j++) {
      if(ord($buffer[$j]) < 0x20 || ord($buffer[$j]) > 0x7F) {
        $returnString = $returnString . ".";
      } else {
        $returnString = $returnString . $buffer[$j];
      }
    }
    $returnString = $returnString . "\n";
    $returnString = $returnString . "Length: " . strlen($buffer) . "\n";
    return "<pre>" . $returnString . "</pre>";
  }
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.