note 96891 deleted from function.rawurldecode by danbrown
| From: | danbrown@php.net | Date: | Sun, 21 Mar 2010 19:26:38 +0000 |
| Subject: | note 96891 deleted from function.rawurldecode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167276@lists.php.net to get a copy of this message | ||
Note Submitter: Drake
----
Sorry, ut's the good version:
<?php
class PhpHex2Str
{
private $strings;
private function x_hex2str($hex) {
$hex = substr($hex[0], 1);
$str = '';
for($i=0;$i < strlen($hex);$i+=2) {
$str.=chr(hexdec(substr($hex,$i,2)));
}
return $str;
}
public function decode($strings = null) {
$this->strings = (string) $strings;
return preg_replace_callback('#\%[a-zA-Z0-9]{2}#', array(get_class($this),
'x_hex2str'), $this->strings);
}
}
// Example
$strings = 'a %20 b%0A h %27 h %23';
$obj = new PhpHex2Str;
$strings = $obj->decode($strings);
var_dump($strings);
?>