繁体   English   中英

jwplayer的preg_match文件URL

[英]preg_match file url from jwplayer

我使用简单的HTML DOM解析器从页面获取html。

现在,我想从<script></script>标记中抓取文件URL。 这是我得到的:

<script type="text/javascript">
    jwplayer("ContainerFlashPlayer").setup({
        'autostart': 'true',
        'primary': 'html5',
        'flashplayer': '/images/embed/player.5.10.swf',
        'file':'/zxdfgdfr44444/afrah/Basem_elkerbelay/selawat/guivvahpasjp.mp3',
        'duration': '356.64975',
        'image': '/images/flashimg.png',
        'volume': '75',
        'height': '240',
        'width': '330',
        'controlbar': 'bottom',
        'stretching': 'fill',
        'skin': '/images/embed/skin/shiavoice1.2.zip'
    }); 

</script>

现在,我想获取文件的URL。 我该怎么做?

你可以做...

<?php
$string = "jwplayer(\"ContainerFlashPlayer\").setup({

 'autostart': 'true',
 'primary': 'html5',
 'flashplayer': '/images/embed/player.5.10.swf',
 'file':'/zxdfgdfr44444/afrah/Basem_elkerbelay/selawat/guivvahpasjp.mp3',
 'duration': '356.64975',
 'image': '/images/flashimg.png',
 'volume': '75',
 'height': '240',
 'width': '330',
 'controlbar': 'bottom',
 'stretching': 'fill',
'skin': '/images/embed/skin/shiavoice1.2.zip' 

});";
preg_match("~^\s*'file'\s*:\s*'(.*?)',?\s*$~m", $string, $file);
echo $file[1];

输出:

/zxdfgdfr44444/afrah/Basem_elkerbelay/selawat/guivvahpasjp.mp3

该正则表达式怎么说?

^行首

\\s*任意数量的空格字符

搜索以下实际文本'file'

同样,任意数量的空格字符都用冒号分隔\\s*:\\s*

然后用单引号将其之间的所有内容与下一个单引号'(.*?)'

可选逗号,可选空格,然后行尾,?\\s*$

右定界符后的m是正则表达式,将每行作为自己的行进行搜索。

http://php.net/manual/en/reference.pcre.pattern.modifiers.php http://php.net/manual/en/function.preg-match.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM