note 24774 modified in function.str-replace by aidan
| From: | aidan@php.net | Date: | Sat, 26 Jun 2004 14:03:13 +0000 |
| Subject: | note 24774 modified in function.str-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71774@lists.php.net to get a copy of this message | ||
I made this to parse values returned in a form, but to preserve formatting so that it doesn't
get removed in the "remove anything but alphanumeric" line... Probably not elegant, but
it works.
<?php
foreach ($_POST as $key => $val)
{
$val = preg_replace("(\r\n|\n|\r)", "#", $val);
$val = preg_replace("/[^0-9a-z -#]/i",'', $val); // strip anything we
don't want
$val = str_replace("#", "*", $val); // * Put a p or br here.
$_POST[$key] = $val;
}
?>
--was--
I made this to parse values returned in a form, but to preserve formatting so that it doesn't
get removed in the "remove anything but alphanumeric" line... Probably not elegant, but
it works.
foreach ($_POST as $key => $val)
{
$val = preg_replace("(\r\n|\n|\r)", "#", $val);
$val = preg_replace("/[^0-9a-z -#]/i",'', $val); // strip anything we
don't want
$val = str_replace("#", "*", $val); // * Put a p or br here.
$_POST[$key] = $val;
}
http://php.net/manual/en/function.str-replace.php