Here is an example of a PHP template parsing.
With regular expressions, the
{Youku Id_xmtc5odgwota4} goes 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}
';
$cfgYouku = Array ("Rege" = "/\s*\{youku\s*id_ (. *)}\s*/i", "callback" and "compile");
foreach ($cfgYouku 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 = "http://v.youku.com/player/getplaylist/videoids/{$matches [1]}/timezone/+08/version/5/source/out?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;
}
http://www.bkjia.com/PHPjc/477897.html www.bkjia.com true http://www.bkjia.com/PHPjc/477897.html techarticle Here is an example of a PHP template parsing. The {Youku id_xmtc5odgwota4} is transferred to the corresponding playback code through the regular expression. PHP header (content-type:text/html; charset=utf-8); $te ...