Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Str替换函数_Php_Mysql - Fatal编程技术网

Php Str替换函数

Php Str替换函数,php,mysql,Php,Mysql,我想检查表单字符串中的单词,并使用sql数据库控制检查单词。以下是我目前掌握的情况: while ($bad_w = mysql_fetch_array($result_badw)) { $newmessage = str_replace($bad_w['word'],"****",$org); } 有没有关于如何更正的想法?每次替换新单词时,您都会覆盖$newmessage 您还应该使用str\u ireplace(),它不区分大小写-这对审查更有利 像这样尝试: $newmessa

我想检查表单字符串中的单词,并使用sql数据库控制检查单词。以下是我目前掌握的情况:

while ($bad_w = mysql_fetch_array($result_badw)) {
    $newmessage = str_replace($bad_w['word'],"****",$org);
}

有没有关于如何更正的想法?

每次替换新单词时,您都会覆盖
$newmessage

您还应该使用
str\u ireplace()
,它不区分大小写-这对审查更有利

像这样尝试:

$newmessage = $org;

while($row = mysql_fetch_array($result_badw)) {
    $newmessage = str_ireplace($row['word'], "****", $newmessage);
}

或者,如果您想要与坏单词中的字母数量相同的
*

$newmessage = $org;

while($row = mysql_fetch_array($result_badw)) {
    $bword = $row['word'];
    $repl = str_repeat('*', strlen($bword));

    $newmessage = str_ireplace($bword, $repl, $newmessage);
}

在替换中重复使用原始字符串。您应该覆盖字符串
$org=str_replace($bad_w['word'],“****”,$org)
)以确保过滤所有单词


只希望没有人在你的论坛上谈论黑潮:p

你面临的问题是什么?只要看看代码,即使没有解释也很明显。@MightyPork added..无意义的练习。当涉及到坏话时,你的过滤器永远无法与人们的创造力相匹配。过滤器是sµCK3R!改为实施标记系统。另一方面,从PHP5.5开始,ext/mysql就不推荐使用。谢谢。。现在为我工作:)编辑它,确保您使用
str\u-ireplace
谢谢!:)工作