使用PHP删除嵌入代码的一部分

时间:2016-06-06 16:44:42

标签: php regex string embed jwplayer

我正在尝试搜索像这样的JW Player嵌入代码:

<iframe src="//content.jwplatform.com/players/ewQYJ6zA-F6KYzWLn.html" width="480" height="270" frameborder="0" scrolling="auto" allowfullscreen></iframe>

我需要抓取的是players/之后的代码,此嵌入中的代码只是ewQYJ6zA

任何人都知道如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

PHP中的这个正则表达式可以解决这个问题:

preg_match('/players\/(.+)-/im', $codetomatch, $codeyouwant);

Regex101

答案 1 :(得分:2)

这将搜索玩家/后跟一个或多个字母和数字。

 <?php
    $string = '<iframe src="//content.jwplatform.com/players/ewQYJ6zA-F6KYzWLn.html" width="480" height="270" frameborder="0" scrolling="auto" allowfullscreen></iframe>';
    preg_match( '~/players/([[a-zA-Z\d]+)~', $string, $matches );
    echo $matches[1];
?>

<强>输出:  ewQYJ6zA