Html src =一个php变量

时间:2014-03-10 19:30:02

标签: php html variables iframe src

你好,我看了一下解决方案,但找不到像我这样的确切问题的人。基本上我有一个php变量是一个url。我想用该网址添加新的iframe。

这就是我所拥有的,但由于HTML在src之后使用双引号,因此忽略了php变量。

<iframe width="420" height="345"src= "<?php $output ?>"> </iframe>

谢谢你们

2 个答案:

答案 0 :(得分:5)

<iframe width="420" height="345" src="<?php echo htmlspecialchars($output); ?>"> </iframe>

你错过了echo。此外,始终使用htmlspecialchars()来确保您创建不易受注入攻击的有效HTML。如果您发现自己经常这样做,请考虑使用模板引擎。

答案 1 :(得分:0)

<iframe width="420" height="345" src="<?php echo htmlspecialchars($output); ?>"> </iframe>