<?php
  function  GetSQLValuestring ($theValue  ,$thetype)
  {
   $theValue=(!get_magic_quotes_gpc()) ?addslashes() : $theValue;
    switch ($thetype)
    {
     case "text":
      $theValue=($theValue != '') ? "'" .$theValue."'" : "null";
     case " int" :
       $theValue=($theValue != '') ? intval($theValue) : "null";
       break;
    }
    return $theValue;
  }
  ?>

 

 

 

get_magic_quotes_gpc函数

                                       
function html($str)
{
     $str = get_magic_quotes_gpc()?$str:addslashes($str);
     return $str;
}
----------------
get_magic_quotes_gpc
取得 PHP 环境变数 magic_quotes_gpc 的值。
语法: long get_magic_quotes_gpc(void);
传回值: 长整数
函式种类: PHP 系统功能
内容说明
本函式取得 PHP 环境设定的变数 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。传回 0 表示关闭本功能;传回 1 表示本功能开启。当 magic_quotes_gpc 开启时,所有的 ' (单引号), " (双引号), \ (反斜线) and 空字符会自动转为含有反斜线的溢出字符。
-----------------------
addslashes -- 使用反斜线引用字符串

描述
string addslashes ( string str)

返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)。

一个使用 addslashes() 的例子是当你要往数据库中输入数据时。例如,将名字 O'reilly 插入到数据库中,这就需要对其进行转义。大多数据库使用 \ 作为转义符:O\'reilly。这样可以将数据放入数据库中,而不会插入额外的 \。当 PHP 指令 magic_quotes_sybase 被设置成 on 时,意味着插入 ' 时将使用 ' 进行转义。

默认情况下,PHP 指令 magic_quotes_gpc 为 on,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

例子 1. addslashes() 示例
$str = "Is your name O'reilly?";

// 输出:Is your name O\'reilly?
echo addslashes($str);
?>

get_magic_quotes_gpc()
本函数取得 PHP 环境配置的变量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。返回 0 表示关闭本功能;返回 1 表示本功能打开。当 magic_quotes_gpc 打开时,所有的 ' (单引号), " (双引号), \ (反斜线) and 空字符会自动转为含有反斜线的溢出字符。