2015-04-02 75 views
0

我想知道是否有任何方法將文本框的每一行換成div。從自定義屬性文本框中獲取每個值

我創建了一個擴展,它在一個塊中獲取自定義文本框的youtube並將其返回。

例如:

自定義文本框的YouTube包含(每隔IFRAME一個新行):

<iframe width="560" height="315" src="URL_1" allowfullscreen></iframe> 
<iframe width="560" height="315" src="URL_2" allowfullscreen></iframe> 

當我得到的自定義字段

return $_product->getYoutube(); 

我想要的內容它輸出:

<div class"youtube"><iframe width="560" height="315" src="URL_1"...</div> 
<div class"youtube"><iframe width="560" height="315" src="URL_1"...</div> 

希望有人能幫助我。

回答

1

$ _product-> getYoutube()只是返回字符串,所以你可以只使用php函數str_replace。 嘗試類似這樣的:

$content = $_product->getYoutube(); 
//for opening tag 
$content = str_replace("<iframe", '<div class="youtube"><iframe', $content); 
//for closing tag 
$content = str_replace("</iframe>", '</iframe></div>', $content); 
return $content; 
+0

謝謝,這工作得很好! – RoRo 2015-04-02 15:45:47