note 63063 added to function.preg-replace
| From: | felipensp at gmail dot com | Date: | Mon, 13 Mar 2006 05:02:32 +0000 |
| Subject: | note 63063 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105634@lists.php.net to get a copy of this message | ||
Sorry, I don't know English.
Replacing letters of badword for a definite character.
View example:
<?php
function censured($string, $aBadWords, $sChrReplace) {
foreach ($aBadWords as $key => $word) {
// Regexp for case-insensitive and use the functions
$aBadWords[$key] = "/({$word})/ie";
}
// to substitue badwords for definite character
return preg_replace($aBadWords,
"str_repeat('{$sChrReplace}', strlen('\\1'))",
$string
);
}
// To show modifications
print censured('The nick of my friends are rand, v1d4l0k4, P7rk, ferows.',
array('RAND', 'V1D4L0K4', 'P7RK', 'FEROWS'),
'*'
);
?>
----
Server IP: 66.163.161.117
Probable Submitter: 200.222.199.68
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/note/edit/63063
Del: integrated -- http://master.php.net/note/delete/63063/integrated
Del: useless -- http://master.php.net/note/delete/63063/useless
Del: bad code -- http://master.php.net/note/delete/63063/bad+code
Del: spam -- http://master.php.net/note/delete/63063/spam
Del: non-english -- http://master.php.net/note/delete/63063/non-english
Del: in docs -- http://master.php.net/note/delete/63063/in+docs
Del: other reasons-- http://master.php.net/note/delete/63063
Reject -- http://master.php.net/note/reject/63063
Search -- http://master.php.net/manage/user-notes.php