我在我的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