比如 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中不再有這個問題了。