Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #76 - Add hex dump support for trace output wth helper function…
… bw_trace_hexdump
- Loading branch information
1 parent
de9f18d
commit 4e953a3
Showing
5 changed files
with
184 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
if ( !defined( "HEXDUMP_INCLUDED" ) ) { | ||
define( "HEXDUMP_INCLUDED", "1.0.0" ); | ||
|
||
/** | ||
* Hexadecimal dumping functions | ||
* | ||
* Library: hexdump | ||
* Provides: hexdump | ||
* Depends: | ||
* | ||
* Helps you to find those pesky control characters | ||
* | ||
* I first wrote this code in PHP in Sep 2013. It echoed the output. | ||
* Now I need it to be returned as a string, so rewriting as oik_hexdump(). | ||
* Quite a few people look for something similar. https://stackoverflow.com/questions/1057572/how-can-i-get-a-hex-dump-of-a-string-in-php | ||
* | ||
*/ | ||
|
||
/** | ||
* Returns the hex dump of the string | ||
*/ | ||
function oik_hexdump( $string ) { | ||
$hexdump = null; | ||
$count = strlen( $string ); | ||
$hexdump .= $count; | ||
$hexdump .= PHP_EOL; | ||
$lineo = ""; | ||
$hexo = ""; | ||
for ( $i = 1; $i <= $count; $i ++ ) { | ||
$ch = $string[ $i - 1 ]; | ||
if ( ctype_cntrl( $ch ) ) { | ||
$lineo .= "."; | ||
} else { | ||
$lineo .= $ch; | ||
} | ||
$hexo .= bin2hex( $ch ); | ||
$hexo .= " "; | ||
if ( 0 == $i % 20 ) { | ||
$hexdump .= $lineo . " " . $hexo . PHP_EOL; | ||
$lineo = ""; | ||
$hexo = ""; | ||
} | ||
} | ||
$hexdump .= substr( $lineo . str_repeat( ".", 20 ), 0, 20 ); | ||
$hexdump .= " "; | ||
$hexdump .= $hexo; | ||
$hexdump .= PHP_EOL; | ||
|
||
return $hexdump; | ||
} | ||
|
||
/** | ||
* Echoes the hex dump of a string | ||
* @param $string | ||
*/ | ||
function hexdump( $string ) { | ||
echo oik_hexdump( $string ); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.