如何解決 magic_quotes_sybase 配置項對 stripslashes 方法的影響?

來源:互聯網
上載者:User
比如 hello\'s world 經過 addslashes 處理後會變成如下字串:

hello\\\'s world

此時,使用 stripslashes 處理這個字串,如果 magic_quotes_sybase 項未開啟,兩個反斜線將會全部被刪除,即變成如下字串:

hello's world

如果單純地通過 ini_set('magic_quotes_sybase', 0); 則會改變當前系統的配置項,有沒有辦法在不改變 magic_quotes_sybase 值的情況下,得到最原始的只包含一個反斜線單字串(hello\'s world),該怎麼破呢?

參考文檔:http://cn2.php.net/manual/zh/function.stripslashes.php

回複內容:

比如 hello\'s world 經過 addslashes 處理後會變成如下字串:

hello\\\'s world

此時,使用 stripslashes 處理這個字串,如果 magic_quotes_sybase 項未開啟,兩個反斜線將會全部被刪除,即變成如下字串:

hello's world

如果單純地通過 ini_set('magic_quotes_sybase', 0); 則會改變當前系統的配置項,有沒有辦法在不改變 magic_quotes_sybase 值的情況下,得到最原始的只包含一個反斜線單字串(hello\'s world),該怎麼破呢?

參考文檔:http://cn2.php.net/manual/zh/function.stripslashes.php

get_magic_quotes_gpc()函數動態檢測。

另外ini_set()函數本來就是指令碼內部有效啊。要是php設定誰都能改那還不翻天了……

WordPress的實踐就是用ini_set()把不把握的預設設定拆了:(WP 3.8 /wp-settings.php源碼)

// Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.@ini_set( 'magic_quotes_runtime', 0 );@ini_set( 'magic_quotes_sybase',  0 );

另外注意:

magic_quotes_sybase
Deprecated in PHP 5.3.0. Removed in PHP 5.4.0.

即在最新的php 5.4中不再有這個問題了。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.