$info=$_POST["info"];
如上,$info中为提交的表单文本,可能含有英文单引号 '
为了能够顺了插入到MySqL中,应该怎么替换呢?谢谢各位前辈~~~

解决方案 »

  1.   

    $info=str_replace("'",'',$info);  //替换成空$info=mysql_real_escape_string($info); //将'转义
      

  2.   

    if (get_magic_quotes_gpc()) 
    {
      $name = stripslashes($info);
    }
    else
    {
      $name = mysql_real_escape_string($info);
    }防sql注入,也可过滤引号等字符的
      

  3.   

    直接这个函数不是更好?
    htmlspecialchars($str);
    取出来在用这个转换
    html_entity_decode($str);<?php
    $orig = "I'll \"walk\" the <b>dog</b> now";$a = htmlentities($orig);$b = html_entity_decode($a);echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; nowecho $b; // I'll "walk" the <b>dog</b> now
    // For users prior to PHP 4.3.0 you may do this:
    function unhtmlentities($string)
    {
        // replace numeric entities
        $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
        $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
        // replace literal entities
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
        $trans_tbl = array_flip($trans_tbl);
        return strtr($string, $trans_tbl);
    }$c = unhtmlentities($a);echo $c; // I'll "walk" the <b>dog</b> now?>