我正在编写一个脚本来查找内容中以下短代码的第一次出现,然后获取短代码的 url 参数。
简码看起来像这样
[soundcloud url="http://api.soundcloud.com/tracks/106046968"]
而我目前所做的是
$pattern = get_shortcode_regex();
$matches = array();
preg_match("/$pattern/s", get_the_content(), $matches);
print_r($matches);
结果看起来像
Array (
[0] => [soundcloud url="http://api.soundcloud.com/tracks/106046968"]
[1] =>
[2] => soundcloud
[3] => url="http://api.soundcloud.com/tracks/106046968"
[4] =>
[5] =>
[6] =>
)
这是我需要短代码参数的url的字符串
$html = 'Our good homies <a href="https://www.facebook.com/yungskeeter">DJ Skeet Skeet aka Yung Skeeter</a> & <a href="https://www.facebook.com/WaxMotif">Wax Motif</a> have teamed up to do a colossal 2-track EP and we\'re getting the exclusive sneak-premiere of the EP\'s diabolical techno b-side called "Hush Hush" before its released tomorrow on <a href="https://www.facebook.com/dimmakrecs">Dim Mak Records</a>!
[soundcloud url="http://api.soundcloud.com/tracks/104477594"]
<a href="https://www.facebook.com/WaxMotif">Wax Motif</a> have teamed up to do a colossal 2-track EP and we\'re getting the exclusive sneak-premiere of the EP\'s diabolical techno b-side called "Hush Hush" before its released tomorrow on <a href="https://www.facebook.com/dimmakrecs">Dim Mak Records</a>!
';
我想这不是最好的方法。如果可以指导我如何做到这一点,那就太好了。基本上我想从内容中提取第一次出现的 soundcloud url。