我在我的iFrame中有一个URL:将字符串添加到iframe标记中的URL结尾
<iframe src="http://example.com/video/123/"></iframe>
。
在PHP中,如何编辑此项以将?wmode=transparent
添加到URL的末尾。
谢谢
我在我的iFrame中有一个URL:将字符串添加到iframe标记中的URL结尾
<iframe src="http://example.com/video/123/"></iframe>
。
在PHP中,如何编辑此项以将?wmode=transparent
添加到URL的末尾。
谢谢
比方说,你已经有了一个PHP页面,将打印以下的html:
<iframe src="http://example.com/video/123/"></iframe>
用PHP,你可以做很多事情,如例如:
<?php
$myVarToAppend = "?wmode=transparent"; //Putting the val inside a variable.
?>
<iframe src="http://example.com/video/123/<?php print $myVarToAppend; ?>"></iframe>
var可以填充很多东西,比如DataBase Response或者你想要的东西。 这就是说,如果你需要这样做运行时(不重新加载页面),你需要使用Javascript
做编辑: 我选择,因为它是最好只在需要时使用PHP不打印所有的字符串,用它打印一切都没有收获。
EDIT2: 您的评论后,你说你有两个字符串:
注意,您的如下书面串不工作好,“被错误的推杆
$string = "<p>test</p><iframe src="http://example.com/video/123/"></iframe><p>test</p>";
和
$toAdd = "?wmode=transparent";
你能做到这样: 我使用的字符串的链接
。$string = '<p>test</p><iframe src="http://example.com/video/123/'.$toAdd.'"></iframe><p>test</p>';
也可能有其他方法,但只有很少的信息是我现在可以做的最大限度。
谢谢,Marco!我的代码可能是'$ string =“
test
你有两个字符串? – 2014-11-24 14:19:43
我用这个作为我的答案的基础:http://stackoverflow.com/questions/11368129/php-preg-replace-to-add-query-param-to-any-urls-of-a-certain -域 – michaelmcgurk 2014-11-24 14:29:27
你可以在url中回显字符串。
<iframe src="http://example.com/video/123/<?php echo "?wmode=transparent" ?>></iframe>
说明“我该如何编辑这个”?请给我们一些背景情况? – Gabriel 2014-11-24 14:10:12
您需要预先制作带有iframe标签的html并对其进行修改?然后使用[DOM](http://php.net/dom)。否则,如果您正在构建该iframe,那么只需将该额外位加入即可。 – 2014-11-24 14:10:40
使用php,您无法编辑现有的html。你可以做的是有不同的case语句来打印写代码。 – wayzz 2014-11-24 14:11:17