The following is an example of php template parsing. Use a regular expression to Convert {youkuid_XMTc5ODgwOTA4} to the corresponding playback code. & Lt ;? Phpheader (& amp; #39; Content-type: text/html; charsetutf-8 & amp; #39;); $ template & amp; #39; {youkuid
The following is an example of php template parsing.
Use a regular expression
{Youku id_XMTc5ODgwOTA4} refers to the corresponding playback code.
Header ('content-type: text/html; charset = utf-8 ');
$ Template ='
{Youku id_XMTc5ODgwOTA4}
{Youku id_XMzA5NTUwOTky}
{Youku id_XMzEwMTQyMjA4}
{Youku id_XMjYzNTE0MTA4}
{Youku id_XMzEwNDMwODk2}
{Youku id_XMjk4NjA3Njk2}
{Youku id_XMjQ3ODQwNDYw}
{Youku id_XMjk4MjA2NDI0}
{Youku id_XMzEwNDIyMTY4}
{Youku id_XMzA5ODUzMjI4}
{Youku id_XMzEwMzMxNjc2}
{Youku id_XMzEwMTk4Njky}
{Youku id_XMTA3OTA4MzQw}
{Youku id_XMjQ1NzI1ODcy}
{Youku id_XMjI4Mzc0OTY0}
';
$ Export youku = array ("rege" => "/\ s * \ {youku \ s * id _(. *)} \ s */I "," callback "=>" compile "));
Foreach ($ export Youku as $ val ){
If (isset ($ val ["callback"])
{
$ Template = preg_replace_callback ($ val ["rege"], $ val ["callback"], $ template );
}
}
/**
*
* Forjobs
* @ Param unknown_type $ matched
*/
Function compile ($ matched)
{
$ Url = $ matched [0]; www.2cto.com
Preg_match ("/id \ _ (\ w +)/", $ url, $ matches );
If (empty ($ matches )){
Preg_match ("# v_playlist \/#", $ url, $ mat );
If (! $ Mat) return false;
$ Html = self: _ fget ($ url );
Preg_match ("# videoId2 \ s * = \ s * \ '(\ w +) \' #", $ html, $ matches );
If (! $ Matches) return false;
}
$ Link = "links? Password = & ran = 2513 & n = 3 ";
$ Retval = fileGetContent ($ link );
If ($ retval ){
$ Json = json_decode ($ retval, true );
$ Data ['IMG '] = $ json ['data'] [0] ['logo'];
$ Data ['title'] = $ json ['data'] [0] ['title'];
$ Data ['URL'] = $ url;
$ Data ['swf '] = "http://player.youku.com/player.php/sid/?#matches=1##/v.swf ";
If ($ data) $ data ['object'] = "". $ data ['title']. ""."";
Return $ data ['object'];
} Else {
Return false;
}
}
/**
*
* @ Author murain
* @ Param String $ url
*/
Function fileGetContent ($ url)
{
$ Ch = curl_init ();
$ Timeout = 10;
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
$ Contents = trim (curl_exec ($ ch ));
Curl_close ($ ch );
Return $ contents;
}