Skip to content

Instantly share code, notes, and snippets.

@mgng
Created February 6, 2012 02:19
Show Gist options
  • Save mgng/1748982 to your computer and use it in GitHub Desktop.
Save mgng/1748982 to your computer and use it in GitHub Desktop.
ヌルバイト削除するやつメモ
<?php
function removeNulByte( $param ) {
if ( is_array( $param ) ) {
$buf = array();
foreach( $param as $key => $val ) {
$buf[ removeNulByte($key) ] = removeNulByte( $val );
}
return $buf;
} else if ( is_string( $param ) ) {
return str_replace("\0", "", $param);
} else {
return $param;
}
}
$a = array(
"a\0b" => "aa\0a",
"a\0c\0" => array(1,2,3,"a\0b\0c\0")
);
foreach($a as $k=>$v){
var_dump($k, $v);
}
$a = removeNulByte( $a );
foreach($a as $k=>$v){
var_dump($k, $v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment