从自定义属性文本框中获取每个值

Get every value from a custom attribute textbox

我想知道是否有任何方法可以将文本框的 每一行 包装成 div.

我创建了一个扩展程序,可以在一个块中获取自定义文本框 youtube 并 returns 它。

例如:

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>

希望有人能帮助我。

$_product->getYoutube() 只是 returns 字符串,所以你可以只使用 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;