我有一个 wordpress 数据库,其中包含一些来自声音云的嵌入式 iframe。我希望将 iframe 替换为某种短代码。我什至创建了一个简码,它工作得很好。
问题是我有一个旧数据库,其中包含大约 2000 个已经嵌入代码的帖子。我想要做的是编写一个代码,以便它将 iframe 替换为简码。
这是我用来从内容中查找 url 的代码,但它总是返回空白。
$string = 'Think Kavinsky meets Futurecop! meets your favorite 80s TV show theme song and you might be pretty close to Swedish producer Johan Bengtsson\'s retro project, <a href="https://soundcloud.com/daataa"><strong>Mitch Murder</strong></a>. Title track, "The Touch," is genuinely lighthearted and fun, crossing over from 80s synth work into a bit of French Touch influence; also including a big time guitar solo straight out of your dad\'s record collection. B-side "Race Day" could very easily be the soundtrack to a video montage of all of your favorite beach scenes from every 80s movie you\'ve ever watched, or as the PR put it, "quite possibly a contender to be the title screen music to a Wave Race 64 sequel." Sounds awesome to me. Also included in this package out today on <a href="https://soundcloud.com/maddecent/">Mad Decent</a>\'s Jeffree\'s sub-label are two remixes of the A-side from Lifelike and Nite Sprite. Download below.
<iframe src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F8087281&color=000000&auto_play=false&show_artwork=true" frameborder="no" scrolling="no" width="100%" height="350"></iframe>';
preg_match("/url=(.*?)/", $string, $matches);
print_r($matches);
上面的代码不起作用,我对正则表达式不太熟悉,所以如果有人能找出这里出了什么问题,那就太好了。而且,如果有人可以指导我正确的流程来做到这一点,那就太好了。