php PHP中iframe的正确格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13920409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:16:08  来源:igfitidea点击:

Proper Format of iframe in PHP?

phpiframe

提问by Kevin Reeves

I'm trying to echo out an iframe in php like this.

我正在尝试像这样在 php 中回显 iframe。

echo
"<li><iframe src=\"http://localhost/ptb1/includes/mod_uploads/profile_pics/index.php" width="188" height="258" scrolling="no" style="overflow:hidden; margin-top:-4px; margin-left:-4px; border:none;\"></iframe></li>";

Whatever I'm doing it's not working. Can someone please tell me the correct way to write this within php?

无论我在做什么,它都不起作用。有人可以告诉我在php中编写它的正确方法吗?

回答by Oldskool

You are not properly escaping the double quotes. You only escape it before the http://bit and all the way at the end, but not in between (which is also necessary). If you encapsulate the HTML between single quotes, you don't have to escape all the double ones. Try it like this:

您没有正确转义双引号。您只能http://在位之前和最后一直逃避它,但不能在两者之间(这也是必要的)。如果将 HTML 封装在单引号之间,则不必转义所有双引号。像这样尝试:

echo '<li><iframe src="http://localhost/ptb1/includes/mod_uploads/profile_pics/index.php" width="188" height="258" scrolling="no" style="overflow:hidden; margin-top:-4px; margin-left:-4px; border:none;"></iframe></li>';

Although, you're not using any variables in your string, so alternatively you can also "step out" of PHP for a bit and just use plain HTML, like:

虽然,您没有在字符串中使用任何变量,因此您也可以暂时“退出”PHP 并仅使用纯 HTML,例如:

<?php
// Your code starts here somehwere, now close the PHP tag
?>
<li><iframe src="http://localhost/ptb1/includes/mod_uploads/profile_pics/index.php" width="188" height="258" scrolling="no" style="overflow:hidden; margin-top:-4px; margin-left:-4px; border:none;"></iframe></li>
<?php
// ... and continue right here

回答by Adam Keenan

Is it because you are only escaping the quote after src=and border:none;instead of every one?

是不是因为你只是在src=border:none;不是每个之后转义报价?

EDIT: And @Oldskool beat me to it xD

编辑:@Oldskool 打败了我 xD

回答by Avinesh Kumar

Try this if you want to display double quotes

如果你想显示双引号试试这个

<?php    
echo "<li><iframe src=\"http://localhost/ptb1/includes/mod_uploads/profile_pics/index.php\" width=\"188\" height=\"258\" scrolling=\"no\" style=\"overflow:hidden; margin-top:-4px; margin-left:-4px; border:none;\"></iframe></li>";
?>