preg_match 来自 jwplayer 的文件 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
这个正则表达式是什么意思?
^
Start of the line
\s*
any number of whitespace characters
Search for the following actual text 'file'
Again any number of whitespace characters with a colon separating it \s*:\s*
A single quote then everything inbetween that and the next single quote '(.*?)'
An optional comma, optional white space and then the end of the line ,?\s*$
The m
after the closing delimiter is so the regex searches each line as its own line.
http://php.net/manual/en/reference.pcre.pattern.modifiers.php
http://php.net/manual/en/function.preg-match.php
我使用简单的 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
这个正则表达式是什么意思?
^
Start of the line
\s*
any number of whitespace charactersSearch for the following actual text
'file'
Again any number of whitespace characters with a colon separating it
\s*:\s*
A single quote then everything inbetween that and the next single quote
'(.*?)'
An optional comma, optional white space and then the end of the line
,?\s*$
The
m
after the closing delimiter is so the regex searches each line as its own line.
http://php.net/manual/en/reference.pcre.pattern.modifiers.php http://php.net/manual/en/function.preg-match.php