被棄用的php函數以及被那個代替

來源:互聯網
上載者:User

標籤:lod   lag   分隔字元   大小寫   reg   nbsp   socket   exp   call   

 原文連結 http://blog.csdn.net/a11085013/article/details/8937848 下面列舉了部分被棄用的函數: 
    call_user_method()(使用 call_user_func() 替代) 
    call_user_method_array() (使用 call_user_func_array() 替代) 
    define_syslog_variables() 
    dl() 
    ereg() (使用 preg_match() 替代) 
    ereg_replace() (使用 preg_replace() 替代) 
    eregi() (使用 preg_match() 配合 ‘i’ 修正符替代) 
    eregi_replace() (使用 preg_replace() 配合 ‘i’ 修正符替代) 
    set_magic_quotes_runtime() 以及它的別名函數  magic_quotes_runtime() 
    [color=olive]session_register() (使用 $_SESSION 超全部變數替代) 
    session_unregister() (使用 $_SESSION 超全部變數替代) 
    session_is_registered() (使用 $_SESSION 超全部變數替代) 
    set_socket_blocking() (使用 stream_set_blocking() 替代) 
    split() (使用 preg_split() 替代) 
    spliti() (使用 preg_split() 配合 ‘i’ 修正符替代) 
    sql_regcase() 
    mysql_db_query() (使用 mysql_select_db() 和  mysql_query() 替代) 
    mysql_escape_string() (使用 mysql_real_escape_string() 替代) 
    廢棄以字串傳遞地區設定名稱. 使用 LC_* 系列常量替代. 
    mktime() 的 is_dst 參數. 使用新的時區處理函數替代. 

涉及到的主要的函數遷移如下: 
刪除函數 define_syslog_variables 引用刪除對函數 define_syslog_variables 的引用將變數 $LOG_ERR, $LOG_USER 等用常量 LOG_USER, LOG_USER, … 替代 
ereg, eregi 函數用 preg_match 函數替代這幾個函數的函式宣告int ereg ( string$pattern , string $string [, array &$regs ] ) int eregi ( string $pattern , string $string [, array &$regs ] ) intpreg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )雖然三者的第一個參數都是字串,表示一個Regex,但是 preg_match 用的是 PCRE(Perl 相容的Regex文法):Regex的兩端用一個符號做邊界,如 “/pattern/” 或者 “#pattern#”,eregi 是乎略大小寫匹配,轉換為 preg_match,第一個參數,用PCRE的參數來乎略大小寫,如:”/pattern/i” 或者 “#pattern#i”,兩者的第三個參數返回的匹配的資料結構不同。ereg 的第三個參數在調用結束後,返回的是一個字串數組,分別為完整匹配字串和各個子匹配字串。preg_match 返回的是二維數組,相當於 ereg 的字串數組中的字串在 preg_match 是一個數組,分別儲存匹配值以及匹配位置。如果要進行多次匹配,PHP 提供了 preg_match_all 函數,其第三個參數的傳回值則是一個三維數組. 
ereg_replace, eregi_replace 函數用 preg_replace 函數或者 str_replace 函數來替代和前面的 ereg 替換為 preg_match 類似,第一個參數要進行轉換,頭尾增加一個符號,如:”/pattern/” 或者 “#pattern#”, …eregi_replace 到 preg_replace 的替換,在第一個參數的後面增加Regex參數。如:”/pattern/i” 或者 “#pattern#i”, …如果 ereg_replace 的第一個參數不是Regex,可以用 str_replace 直接來替換。 
spliti 函數用 explode 或則 preg_split 函數替代split 切分字串,如果無須用到Regex,使用 explode 替換是最好不過,速度最快.對於使用Regex切分字串,則使用 preg_split 函數替代。替代過程和 ereg/ereg_replace 類似,只是在第一個Regex參數中做文章,將 split 的Regex前後加上一個 PCRE 的分隔字元號。

被棄用的php函數以及被那個代替

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.