2013-08-28 127 views
0

我正在使用表單從用戶提取iframe代碼並將其插入另一個頁面。但是,當代碼被插入時,它會在混合中插入一個「\」。PHP表單插入代碼

這裏是原代碼:

<iframe src='http://listings.realbird.com/home-search-o/?rb_id=N7T5O2I2&bq=[item type:housing][location:@%22Reno, Nv%22][listing type:housing/sale][property type:/foreclosure]&orderby=price' frameborder='0' width='100%' height='2700' style='width:100%; height:2700px;'></iframe>

這裏是代碼的PHP文件處理後:

<iframe src=\'http://listings.realbird.com/home-search-o/?rb_id=N7T5O2I2&bq=[item type:housing][location:@%22Reno, Nv%22][listing type:housing/sale][property type:/foreclosure]&orderby=price\' frameborder=\'0\' width=\'100%\' height=\'2700\' style=\'width:100%; height:2700px;\'></iframe> 

任何辦法來防止這種情況發生?

+0

使用雙引號!它不喜歡那些單曲,所以它逃避了他們......也就是說,如果你有控制權。 –

回答

1

這看起來像魔術引號給我。你可以嘗試用'&'替換所有的實例;

或可考慮PHP的方法stripslashes

0

到這裏看看: http://www.dreamincode.net/forums/topic/147880-does-php-5-automatically-addslashes/

一些PHP默認配置是自動添加上提交表格上的內容斜槓因此,這將是「更安全」的工作如果你想將它插入數據庫或類似的東西的話。

如果你想阻止這種行爲,我認爲你可以通過使用類似下面的內容來關閉整個php應用程序:set_magic_quotes_runtime(false);

http://www.php.net/manual/en/function.set-magic-quotes-runtime.php

試試看吧。

+0

如果你閱讀更多,你可以看到,這種行爲將消失在較新的PHP版本,所以你可能想要檢查你的腳本在不同的PHP版本,如果它將被要求,以確保它仍然工作,不會拋棄你過時注意 –