$variable = str_replace("\","& #92;",$variable); $variable = str_replace("'","& #39;",$variable); $sql = "select campo from tabla where campo = '$variable' ; "