I have this function cleaning strings for SQL injection
function _clean($clean) {
$clean = utf8_encode($clean);
$array_find = array( "(" , ")" , "," , "#" , "'" , "@" , ";" , ":" , "&");
$array_replace = array("\x28","\x29","\x82","\x23","\x27","@","\x3B","\x3A","&")
$cleaned = str_replace( $array_find,$array_replace, $clean);
return $cleaned;
}
It works well but am noting cases where I have $cleaned = _clean("Relaxin'");
returns cleaned as "Relaxin'";
It fails to remove this single quote I am unsure why as I am converting to utf8. Does anyone have any ideas as I might have to re-write str_replace()
?
I did try this first:
//uses https://www.ascii-code.com/
function _clean($clean)
{
$clean = utf8_encode($clean);
$array_find = array( "(" , ")" , "," , "#" , "'" , "@" , ";" , ":" , "&");
$array_replace = array("(",")",",","#","'","@",";",":","&");
$cleaned =
str_replace( $array_find,$array_replace, $clean);
return $cleaned;
}
leaving funny characters in when it was converted back to output to the internet 'Erotic Lounge (Bare Pearls) becomes 'Erotic Lounge &ුBare Pearls&' for some reason the brackets don't come back on screen.
I tried this
$array_replace = array("&(",")",",","#","'","@",";",":","&"); ad all seems ok.
Am still not getting ',' substituted ending up with silly characters '&ෘ'
for example in "Covers, Vol. 1" ends up "Covers&ෘ Vol. 1"
Does anyone know why it does this on the web page please .
function _clean($clean) {
$clean = utf8_encode($clean);
$array_find = array("è", "ê", "é", "(" , ")" , "," , "#" , "'" , "@" , ";" , ":" , "&");
$array_replace = array("è","ê","é","(",")",",","#","'","@",";",":","&");
$cleaned = str_replace( $array_find,$array_replace, $clean);
return $cleaned;
}