ascii_strip.phps
- <?php
-
- // Strip non-printable characters
- function strip_ascii($string, $pad = '') {
- $ret = "";
- $len = strlen($string);
- for($a=0; $a<$len; $a++) {
- $p = ord($string[$a]);
- (($p > 31 && $p < 127)) ? $ret .= $string[$a] : $ret .= $pad;
- }
- return $ret;
- }
-
- // Strip all but the specified allowed characters from string
- function strip($data, $allowed) {
- if (strlen($data) == 0 || strlen($allowed) == 0) {
- return false;
- }
- foreach (str_split($allowed) as $char) {
- $arrAllow[ord($char)] = $char;
- }
- $result = '';
- foreach (str_split($data) as $char) {
- if (isset($arrAllow[ord($char)])) {
- $result .= $char;
- }
- }
- return $result;
- }
-
-
-
- ?>