Created
January 21, 2011 06:47
-
-
Save kunit/789333 to your computer and use it in GitHub Desktop.
元が配列である前提で解析して、最後の最後で _raw_xxx というキーを入れる
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
<?php | |
class Foo { | |
function h($text) { | |
$result = array(); | |
$charset = 'UTF-8'; | |
$this->_escape($text, $result, $charset); | |
return $result; | |
} | |
function _escape($values, &$result, $charset) { | |
foreach ($values as $key => $value) { | |
if (is_object($value)) { | |
$result[$key] = $value; | |
} else if (is_array($value)) { | |
$result[$key] = array(); | |
$this->_escape($value, $result[$key], $charset); | |
} else { | |
$result[$key] = htmlspecialchars($value, ENT_QUOTES, $charset); | |
$result["_raw_{$key}"] = $value; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment