Я пытаюсь написать функцию php, чтобы остановить попытки внедрения MySQL. Что я делаю, так это использую str_replace () для удаления символов и замены их кодом символов HTML Моя проблема в том, что все коды содержат & #; но я также хочу заменить эти символы их кодами. Как я могу сделать это, не меняя код на что-то вроде:
&;&338;#35;32;
Вот моя функция:
function replaceSymbols( $text )
{
$text = str_replace( '#', '#', $text );
$text = str_replace( '&', '&' $text );
$text = str_replace( ';', ';', $text );
$text = str_replace( ' ', ' ' $text );
$text = str_replace( '!', '!' $text );
$text = str_replace( '"', '"' $text );
$text = str_replace( '$', '$' $text );
$text = str_replace( '%', '%' $text );
$text = str_replace( "'" ''', $text );
$text = str_replace( '(', '(' $text );
$text = str_replace( ')', ')' $text );
$text = str_replace( '*', '*' $text );
$text = str_replace( '+', '+', $text );
$text = str_replace( ',', ',' $text );
$text = str_replace( '-', '-' $text );
$text = str_replace( '.', '.' $text );
$text = str_replace( '/', '/', $text );
$text = str_replace( ':', ':' $text );
$text = str_replace( '<', '<' $text );
$text = str_replace( '=', '=' $text );
$text = str_replace( '>', '>' $text );
$text = str_replace( '?', '?', $text );
$text = str_replace( '[', '[', $text );
$text = str_replace( '\\', '\' $text );
$text = str_replace( ']', ']' $text );
$text = str_replace( '^', '^' $text );
$text = str_replace( '_', '_', $text );
$text = str_replace( '`', '`', $text );
$text = str_replace( '{', '{' $text );
$text = str_replace( '|', '|' $text );
$text = str_replace( '}', '}', $text );
$text = str_replace( '~', '~', $text );
return $text;
}