簡體   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