1 頁 (共 1 頁)

5.2 Upgrade to 5.3

發表於 : 2011-08-03 09:28:29
yehlu
1.變更 session 函式

代碼: 選擇全部

function session_is_registered1($sess){
    if(isset($_SESSION[$sess])){
        return true;
    }else{
        return false;
    }
}
function session_unregister1($sess){
    unset($_SESSION[$sess]);
}
function session_register1($sess){
    if(!isset($_SESSION[$sess])){
        $_SESSION[$sess] = $$sess;
    }
}
2.新增自動展開 _GET _POST _SESSION

代碼: 選擇全部

if(count($_SESSION) > 0){
  foreach($_SESSION as $sesskey => $sessvalue){
      $$sesskey = $sessvalue;
  }
}
if(count($_GET) > 0){
  foreach($_GET as $getkey => $getvalue){
      $$getkey = $getvalue;
  }
}
if(count($_POST) > 0){
  foreach($_POST as $postkey => $postvalue){
      $$postkey = $postvalue;
  }
}
3.修改 CCS 的 common.php 中的函式

代碼: 選擇全部

function get_param($param_name)
{
  $param_value = "";
  if(isset($_POST[$param_name]))
    $param_value = $_POST[$param_name];
  else if(isset($_GET[$param_name]))
    $param_value = $_GET[$param_name];

  return $param_value;
}
function get_session($param_name)
{
  return $_SESSION[$param_name];
}

function set_session($param_name, $param_value)
{
    unset($_SESSION[$param_name]);
    $_SESSION[$param_name] = $param_value;
}


4.變更ereg 為 preg_match

代碼: 選擇全部

'ereg("[A-Z][A-Z][0-9]{8}",' 為 'preg_match("/^[A-Z]{1}[A-Z]{1}[0-9]{8}$/",',
5.變更split 為 explode

6.變更ereg_replace 為preg_replace

eregi 改為 preg_match

代碼: 選擇全部

if(!eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $str)) {
    $msg = 'email is not valid';

} 

 

改一下後:
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $str)) {
    $msg = 'email is not valid';

}