30
readarg
readarg
SYNOPSIS
readarg($s, $trim=true, $strip=true)
DESCRIPTION
readarg returns the string $s trimmed of leading and trailing whitespace characters if $trim is true and stripped of HTML and PHP tags if $strip is true.
If $s is an array, readarg applies itself recursively to all its elements with the same arguments.
NOTE: readarg is used to filter $_GET and $_POST arguments received in HTTP GET and POST requests.
EXAMPLE
php > require 'library/readarg.php';
php > $arg=" <b>Hello!</b> ";
php > var_dump(readarg($arg));
string(6) "Hello!"
CODE
- function readarg($s, $trim=true, $strip=true) {
- if (is_array($s)) {
- return array_map('readarg', $s, array_fill(0, count($s), $trim), array_fill(0, count($s), $strip));
- }
- if ($trim) {
- $s = trim($s);
- }
- if ($strip) {
- $s = strip_tags($s);
- }
- return $s;
- }
Comments