2013-08-28 128 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版本,如果它将被要求,以确保它仍然工作,不会抛弃你过时注意 –