我想从一个Object/Embed HTML源代码中获取视频URL,我知道可以使用正则表达式来获取,但是我和正则表达式不太熟悉。
这是我的源代码:
<?php
function src($text) {
$text = str_replace('"', '', $text);
$text = str_replace('src=', '', $text);
$temporary = explode('<embed', $text);
$temporary = $temporary[1];
$temporary = explode(' ', trim($temporary));
return $temporary[0];
}
$html = '
<object width="180" height="220">
<param name="movie" value="http://www.domain.com/video/video1.swf"></param>
<embed src="http://www.domain.com/video/video1.swf" type="application/x-shockwave-flash" width="180" height="220"></embed>
</object>
';
echo src($html);
这个有效,但用正则表达式会更好吗?我正在使用 lamp。
["|\']
子表达式...|
字符在字符类中 不是 元字符(您不能在字符类中进行选择)。您想要的只是["']
。 - ridgerunner?
的意思是非贪婪模式,不要贪心。 - user938787