$search = array("<?php", "god", "gOd"); //do not want to do this in so many words\\
$replace = array("<-php", "God", "God");
$comment = str_replace($search, $replace, mysqli_real_escape_string($conexao, $_POST['comment']));
I want to include uppercase and lowercase letters in the array, how to do this for $search
and $replace
?
If you have to use regular expressions, write your code like this:
preg_replace('/regular expression here/i', 'replacement here', $string);
Otherwise use str_ireplace()
: http://php.net/manual/en/function.str-ireplace.php
<?php
$db = new mysqli('localhost', 'root');
$a = array("<?php", "god", "gOd");
foreach ($a as &$v) {
$v = mysqli_real_escape_string(
$db,
preg_replace("/[^A-Za-z0-9?!]/", '', $v)
);
}
var_export($a);
Result:
array (
0 => '?php',
1 => 'god',
2 => 'gOd',
)