【问题标题】:Search for iframe replace with shortcode搜索 iframe 替换为简码
【发布时间】:2013-11-19 14:33:37
【问题描述】:

我正在尝试将所有 iframe 从数据库转换为 wordpress 简码。这是一个示例字符串

<iframe src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F59701079&amp;auto_play=false&amp;show_artwork=true&amp;color=00adee" frameborder="no" scrolling="no" width="100%" height="166"></iframe>came over from Berlin for a couple of days. Mad fun that guy is!! We actually made 2 tracks during his stay here. The other one will be released soon.<iframe src="http://www.youtube.com/embed/z3fIsvQDrqI" frameborder="0" width="460" height="259"></iframe>\r\n<strong><span style="color: #3366ff;">GDD:</span></strong> So wild! Well we''re very happy you''re getting the deserved attention! Tell us what you have coming up next in the Kill Frenzy world!\r\n<span style="color: #ff0000;"><strong>KF:</strong></span><iframe src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F53146049&amp;auto_play=false&amp;show_artwork=true&amp;color=00adee" frameborder="no" scrolling="no" width="100%" height="166"></iframe>

基本上我要做的是转换

&lt;iframe src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F59701079&amp;amp;auto_play=false&amp;amp;show_artwork=true&amp;amp;color=00adee" frameborder="no" scrolling="no" width="100%" height="166"&gt;&lt;/iframe&gt;

[soundcloud url="http://api.soundcloud.com/tracks/59701079"]

所以最终字符串会被转换成这样的东西

[soundcloud url="http://api.soundcloud.com/tracks/59701079"] came over from Berlin for a couple of days. Mad fun that guy is!! We actually made 2 tracks during his stay here. The other one will be released soon.<iframe src="http://www.youtube.com/embed/z3fIsvQDrqI" frameborder="0" width="460" height="259"></iframe>\r\n<strong><span style="color: #3366ff;">GDD:</span></strong> So wild! Well we''re very happy you''re getting the deserved attention! Tell us what you have coming up next in the Kill Frenzy world!\r\n<span style="color: #ff0000;"><strong>KF:</strong></span>[soundcloud url="http://api.soundcloud.com/tracks/5314604"]

其实我已经问过类似的问题here

当字符串中只有一个 iframe 时有效。当有多个 iframe 时,它​​会显示一些奇怪的结果。当有其他 iframe 像 youtube、vimeo 时,它也显示出问题。我浪费了大约 10 个小时,但找不到解决方案。因此,如果任何专家可以帮助我完成这项工作,我将非常感谢您的帮助。

【问题讨论】:

  • 不要在 html 上使用正则表达式。使用 dom 查找 iframe,并将它们替换为包含您的简码的文本节点。
  • 是的,但我无法弄清楚我究竟是如何做到这一点的。这只是一次代码。

标签: php mysql wordpress preg-replace soundcloud


【解决方案1】:

要区分 soundcloud iframe 和其他 iframe,您可以将其设置为“搜索关键字”“搜索和替换以查找所有实例并用您想要的任何内容替换它们。

同样,检查this thread。它不是专门针对 wordpress 的,但您可以看到它如何处理 mysql 数据库中的查找和替换。

【讨论】:

  • 谢谢,但这不仅仅是替换,它是先获取价值然后进行替换。
猜你喜欢
  • 2016-04-27
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 2016-04-22
  • 1970-01-01
  • 2010-11-05
  • 1970-01-01
相关资源
最近更新 更多