2017-10-10 24 views
0

我要替換的Youtube嵌入代碼width="" height=""寬度class="youtube"代替,這樣我可以在CSS中設置新的寬度和YouTube的高度與class="youtube"嵌入如何替換嵌入class =「」的youtube的width =「」和height =「」?

我搜索PHP str_replace()preg_replace()但我仍然不知道太多,他們是正確的使用或我必須使用另一個功能。

更改此:

<iframe width="560" height="315" src="http://" frameborder="0" allowfullscreen></iframe> 

要這樣:

<iframe class="youtube" src="http://" frameborder="0" allowfullscreen></iframe>` 
+0

使用domdocument而不是其他html解析器 – splash58

+0

您是在嘗試使視頻響應還是其他? –

+0

是的,我試圖展示YouTube屏幕尺寸不同的寬度和高度。 – Yuma

回答

1

你不知道的寬度或高度,使你不能使用str_replace函數,但可以的preg_replace解決問題

$newEnbedCode = preg_replace('/width="([0-9]+)" height="([0-9]+)"/', 'class="youtube"', $embedCode); 

working example

相關問題