qesc()
by webproger on 2020-04-02
<?php
function qesc($s,$m) {
    switch($m) {
        case 0:
            $s= str_replace("&" ,"&amp;" ,$s);
            return $s;
        case 8:
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("<" ,"&lt;"  ,$s);
            $s= str_replace(">" ,"&gt;"  ,$s);
            return $s;
        case 9:
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("<" ,"&lt;"  ,$s);
            $s= str_replace(">" ,"&gt;"  ,$s);
            $s= str_replace("\n ","<br>&nbsp;",$s);
            $s= str_replace("\n" ,"<br>",$s);
            $s= str_replace("\t","&nbsp; &nbsp; ",$s);
            $s= str_replace("  " ,"&nbsp; ",$s);
            $s= str_replace("  " ,"&nbsp; ",$s);
            return $s;
        case 1:
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("'" ,"&#039;",$s);
            return $s;
        case 2:
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("\"","&quot;",$s);
            return $s;
        case 3:
            $s= str_replace("\\","\\\\"  ,$s);
            $s= str_replace("'" ,"\'"    ,$s);
            $s= str_replace("\n","\\n"   ,$s);
            $s= str_replace("\r","\\r"   ,$s);
            $s= preg_replace("/<\/(script)>/i","<\\u002F$1>",$s);
            return $s;
        case 4:
            $s= str_replace("\\","\\\\"  ,$s);
            $s= str_replace("\"","\\\""  ,$s);
            $s= str_replace("\n","\\n"   ,$s);
            $s= str_replace("\r","\\r"   ,$s);
            $s= preg_replace("/<\/(script)>/i","<\\u002F$1>",$s);
            return $s;
        case 5:
            $s= str_replace("\\","\\\\"  ,$s);
            $s= str_replace("'" ,"\'"    ,$s);
            $s= str_replace("\n","\\n"   ,$s);
            $s= str_replace("\r","\\r"   ,$s);
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("\"","&quot;",$s);
            return $s;
        case 6:
            $s= str_replace("\\","\\\\"  ,$s);
            $s= str_replace("\"","\\\""  ,$s);
            $s= str_replace("\n","\\n"   ,$s);
            $s= str_replace("\r","\\r"   ,$s);
            $s= str_replace("&" ,"&amp;" ,$s);
            $s= str_replace("'" ,"&#039;",$s);
            return $s;
        case 7:
            $s= mysql_real_escape_string($s);
            return $s;
    }
}
function Q_escape($s,$m) { return qesc($s,$m); }
?>