<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>preg_match_all &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/preg_match_all/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 10:02:54 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>PHP优酷土豆酷6采集入库函数(获取视频缩略图,视频swf地址,视频标题)</title>
		<link>https://www.mudbest.com/%e4%bc%98%e9%85%b7%e5%9c%9f%e8%b1%86%e9%85%b76%e9%87%87%e9%9b%86%e5%85%a5%e5%ba%93%e5%87%bd%e6%95%b0/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Fri, 24 Jun 2011 18:35:01 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[preg_match_all]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=684</guid>

					<description><![CDATA[Demo]]></description>
										<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * 采集入库函数
 * 优酷,土豆,酷6 采集 (自动获取视频缩略图,视频swf地址,视频标题)
 * by hkshadow
 * QQ 2765237
 * dete: 2011-06-25 AM 02:32
 * edit: 2011-06-25 PM 17:38
 */

function CaptureVideo($link, $host) {
	$return = array ();
	if ('youku.com' == $host) {
		header ( &quot;Content-Type:text/html; charset=utf-8&quot; ); //优酷是utf-8编码,只为测试显示正常,可自行删除
		preg_match_all ( &quot;/id\_(\w+)&#x5B;\=|.html]/&quot;, $link, $matches );
		if (! empty ( $matches &#x5B;1] &#x5B;0] )) {
			$return &#x5B;'flashvar'] = $matches &#x5B;1] &#x5B;0];
		}
		$text = file_get_contents ( $link );
		preg_match ( &quot;/&lt;title&gt;(.*?) - (.*)&lt;\/title&gt;/&quot;, $text, $title );
		preg_match_all ( '/&lt;li class=&quot;download&quot;(.*)&lt;\/li&gt;/', $text, $match2 );
		preg_match ( '/http:\/\/g(.*)\.ykimg.com\/(.*)\|&quot;\&gt;/', $match2 &#x5B;1] &#x5B;0], $imageurl );
		if (! empty ( $imageurl &#x5B;1] )) {
			$return &#x5B;'imageurl'] = &quot;http://g&quot; . $imageurl &#x5B;1] . &quot;.ykimg.com/&quot; . $imageurl &#x5B;2];
		}
		preg_match ( '/embed src=\&quot;(.*)\/v.swf/', $text, $vidurls );
		if (! empty ( $vidurls &#x5B;1] )) {
			
			$return &#x5B;'vidurl'] = $vidurls &#x5B;1];
		}
		
		if (! empty ( $title )) {
			$return &#x5B;'title'] = $title &#x5B;1];
		}
	} elseif ('ku6.com' == $host) {
		header ( &quot;Content-Type:text/html; charset=gbk&quot; );  //酷6是gbk编码,只为测试显示正常,可自行删除
		$text = file_get_contents ( $link );
		preg_match_all ( &quot;/\/(&#x5B;\w\-]+)\.html/&quot;, $link, $matches );
		if (1 &gt; preg_match ( &quot;/\/index_(&#x5B;\w\-]+)\.html/&quot;, $link ) &amp;&amp; ! empty ( $matches &#x5B;1] &#x5B;0] )) {
			$return &#x5B;'flashvar'] = $matches &#x5B;1] &#x5B;0];
		} else {
			preg_match_all ( &quot;/refer\/(.*)\/v.swf/&quot;, $text, $videourl );
			$return &#x5B;'flashvar'] = $videourl &#x5B;1] &#x5B;0];
		}
		preg_match ( '/http\:(.*)\/v.swf/', $text, $vidurls );
		if (! empty ( $vidurls &#x5B;0] )) {
			$return &#x5B;'vidurl'] = $vidurls &#x5B;0];
		}
		preg_match ( &quot;/\&quot;title\&quot; content=\&quot;(.*)\&quot;\/&gt;/&quot;, $text, $title );
		preg_match_all ( '/&lt;span class=&quot;s_pic&quot;&gt;(.*)&lt;\/span&gt;/', $text, $imageurl );
		if (! empty ( $imageurl &#x5B;1] &#x5B;0] )) {
			$return &#x5B;'imageurl'] = $imageurl &#x5B;1] &#x5B;0];
		}
		if (! empty ( $title&#x5B;1] )) {
			$return &#x5B;'title'] = $title &#x5B;1];
		}
	} elseif ('tudou.com' == $host) {
		header ( &quot;Content-Type:text/html; charset=gbk&quot; );  //土豆是gbk编码,只为测试显示正常,可自行删除
		$tudou = file_get_contents ( $link );
		preg_match_all ( &quot;/view\/(&#x5B;\w\-]+)\//&quot;, $tudou, $matches );
		
		if (! empty ( $matches &#x5B;1] &#x5B;0] )) {
			$return &#x5B;'flashvar'] = $matches &#x5B;1] &#x5B;0];
		}
		
		preg_match ( &quot;/&lt;title&gt;(.*?)_(.*)&lt;\/title&gt;/&quot;, $tudou, $title );
		
		preg_match ( &quot;/pic:\&quot;(.*)\&quot;/&quot;, $tudou, $imageurl );
		
		preg_match ( &quot;/,lid = (.*)/&quot;, $tudou, $vls );
		preg_match ( '/,lid_code = lcode = (.*)/', $tudou, $tx );
		$ntx = str_replace ( &quot;'&quot;, &quot;&quot;, $tx );
		if (! empty ( $ntx &#x5B;1] ) &amp;&amp; ! empty ( $vls &#x5B;1] )) {
			$return &#x5B;'vidurl'] = &quot;http://www.tudou.com/l/&quot; . $ntx &#x5B;1] . &quot;/&amp;iid=&quot; . $vls &#x5B;1] . &quot;/v.swf&quot;;
		}
		if (! empty ( $imageurl &#x5B;1] )) {
			$return &#x5B;'imageurl'] = $imageurl &#x5B;1];
		}
		if (! empty ( $title )) {
			$return &#x5B;'title'] = $title &#x5B;1];
		}
	}
	return $return;
}
</pre>
<p>Demo</p>
<pre class="brush: php; title: ; notranslate">
//用法如下
//暂只做了土豆,优酷,酷6三种
//由于以上官方不定期变动html结构,如失效请修改相应正则
//by hkshadow 2011-06-25
$link = 'http://v.youku.com/v_show/id_XMjcxNjU0NjMy.html';
$host = &quot;youku.com&quot;;
$text = CaptureVideo ( $link, $host );
print_r ( $text );
?&gt;
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
