搜索iframe替换为shortcode


Search for iframe replace with shortcode

我正在尝试将数据库中的所有iframe转换为wordpress shortcode。这是一个样本字符串

<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>

基本上,我想做的是转换

<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>

[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"]

事实上,我已经在这里问过类似的问题

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

要区分soundcloud iframe和其他iframe,您可以将其设置为"search keyword"search and Replace"以查找所有实例并将其替换为您想要的任何实例。

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