<?php
header("Content-Type: text/html; charset=UTF-8");
libxml_use_internal_errors(true);
//建议php版本7 开启curl扩展
$typeid =$_GET["t"];
$page = $_GET["pg"];
$ids = $_GET["ids"];
$burl = $_GET["url"];
$wd = $_GET["wd"];

//===============================================基础配置开始===========================================
$web='https://www.mgtv.com';
//1=开启搜索  0=关闭搜索 默认关闭搜索
$searchable=1;
//1=开启首页推荐  0=关闭首页推荐
$indexable=1;

//====================以下内容可忽略不修改===================

//如不懂可以不填写
$cookie='';

//当影视详情没有影视图片或取图片失败时，返回该指定的图片链接(不设置的话，缺图时历史记录的主图会空白)
$historyimg='https://www.hjunkel.com/images/nopic2.gif';

//模拟ua 如非不要默认即可
$UserAgent='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36';

//1=开启直链分析  0=关闭直链分析 (直链也是通过本php页面解析) 测试极品关闭直链 大部分能通过webview解析
//该模板的直链代码是针对极品影视的，每个站的直链代码都不同。其他网站请设置为0关闭
$zhilian=0;
//====================以上内容可忽略不修改===================



//===============================================基础配置结束===========================================




//===============================================广告图片配置开始 可以不用修改 默认不开启=======================================
//$adable=1开启广告  $adable=0关闭广告图片  可插入指定图片到每次读取第一页影视列表的开头，默认关闭
$adable=0;
$adpicurl='https://alifei05.cfp.cn/creative/vcg/800/version23/VCG41184086603.jpg';
$adtitle1='我是片名';
$adtitle2='我是更新内容';
//===============================================广告图片配置结束 可以不用修改 默认不开启============================================





//===============================================影视分类相关配置开始===========================
$movietype = '{"class":[{"type_id":"1","type_name":"电 影","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=a1&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"2","type_name":"连续 剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=a1&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"3","type_name":"综艺","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=1&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=a1&area=a1&sort=c1"},{"type_id":"4","type_name":"动漫","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=50&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=a1&area=a1&edition=a1&sort=c1"},{"type_id":"5","type_name":"甜蜜互宠","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=14&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"6","type_name":"古装剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=148&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"7","type_name":"悬疑剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=3002&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"8","type_name":"喜剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=3005&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"9","type_name":"都市职场","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=19&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"10","type_name":"偶像剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=147&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"11","type_name":"谍战剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=3004&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"12","type_name":"家庭剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=3007&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"13","type_name":"青春剧","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=3003&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1"},{"type_id":"14","type_name":"喜剧片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=176&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"15","type_name":"动作片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=177&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"16","type_name":"爱情片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=175&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"17","type_name":"恐怖悬疑","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=43&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"18","type_name":"警匪片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=45&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"20","type_name":"战争片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=44&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"21","type_name":"科幻片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=178&edition=a1&year=all&chargeInfo=a1&sort=c1"},{"type_id":"22","type_name":"动画片","catname":"https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=3&pn={pageid}&pc=80&hudong=1&_support=10000000&kind=48&edition=a1&year=all&chargeInfo=a1&sort=c1"}]}';
//===============================================影视分类相关配置结束===========================


//===============================================首页推荐相关配置开始===========================
$indexnum=50;
//===============================================首页推荐相关配置结束===========================



//===============================================影视搜索相关配置开始===========================
//=========下面把xpath规则的搜索屏蔽了，极品采用json的搜索结果========
$searchtype=1;

//-----------------------------如非必要，下面4项可以不用修改-------------------------------
//影片标题是否精确匹配  1=精确匹配（必须包含搜索文字）  0为关闭精确匹配，显示所有搜索结果
$titlematch=1;
//搜索访问类型 1=get  2=post 一般默认为1
$datatype=1;
//搜索访问提交数据 当$datatype为2时，需要在此处填写提交数据 关键词用{wd}代替
$searchdata='';
//{wd}提交的编码格式  1=utf-8编码  2=gb2312编码(大部分网站默认为utf-8即可)
$convert=1;
//-----------------------------如非必要，上面4项可以不用修改-------------------------------



//===============================================影视搜索相关配置结束===========================
//==============================================仅需修改以上代码↑=======================================


//==============================================以下内容的代码无需修改↓=======================================
$weburl='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if ($typeid<> null && $page<>null){
//==============================================读取影视列表开始=======================================
$catname ='';
$arr=json_decode($movietype,true);
$arr_q1a=$arr['class'];
$m=count($arr_q1a);
 for($i=0;$i<$m;$i++){
 $type_id = $arr_q1a[$i]["type_id"];
 if($typeid==$type_id){
  $catname =  $arr_q1a[$i]["catname"];
  break;
 }
 }
$catname=str_replace('{pageid}',$page,$catname);
$html ='';
for ($i = 0; $i < 3; $i++) {
$html = curl_get($catname,$cookie,$UserAgent);
if($html<>null){
break;
}
}

$arr=json_decode($html,true);
$arr_q1a=$arr['data']['hitDocs'];
$m=count($arr_q1a);
$length=$m;
$guolv='';
if ($adable==1 && $page==1){
$length=$length+1;
}
if ($length<$num)
{
$page2=$page;
}else{
$length=$length+1;
$page2=$page + 1;
}
$result='{"code":1,"page":'.$page.',"pagecount":'. $page2 .',"total":'. $length.',"list":[';
if ($adable==1 && $page==1){
    $result=$result.'{"vod_id":"888888888","vod_name":"'.$adtitle1.'","vod_pic":"'.$adpicurl.'","vod_remarks":"'.$adtitle2.'"},';
}
for ($i = 0; $i < $m; $i++) {
$text=$arr['data']['hitDocs'][$i]['updateInfo'];
if($text==null){
$text=$arr['data']['hitDocs'][$i]['rightCorner']['text'];
}

if($text==null){
$text=$arr['data']['hitDocs'][$i]['year'].'年';
}

$clipId=$arr['data']['hitDocs'][$i]['clipId'];
$playPartId=$arr['data']['hitDocs'][$i]['playPartId'];
$link =$playPartId;
$title =$arr['data']['hitDocs'][$i]['title'];
$pic = $arr['data']['hitDocs'][$i]['img'];
   if (substr($pic,0,2)=='//'){
	$pic = 'https:'.$pic;
	}
	
if($text<>'预告' && $text<>'付费点播' && $text<>'VIP用券'){
if($guolv==null){
	    $result=$result.'{"vod_id":"'.$link.'","vod_name":"'.$title.'","vod_pic":"'.$pic.'","vod_remarks":"'.$text.'"},';
    	$guolv=$guolv."{".$link."}";
}else if(strpos($guolv, "{".$link2."}")===false){
	    $result=$result.'{"vod_id":"'.$link.'","vod_name":"'.$title.'","vod_pic":"'.$pic.'","vod_remarks":"'.$text.'"},';
    	$guolv=$guolv."{".$link."}";
	}
	}
	
	
	
}
$result=substr($result, 0, strlen($result)-1).']}';
echo $result;
//==============================================读取影视列表结束=======================================
}else if ($ids<> null && strpos($ids, ",")===false && strpos($ids, "%2C")===false){
if($ids=='888888888'){
$result='{"list":[{"vod_id":"888888888",';
$result=$result.'"vod_name":"'.$adtitle1.'",';
$result=$result.'"vod_pic":"'.$adpicurl.'",';
$actor='内详';
$result=$result.'"vod_actor":"'.$actor.'",';
$director='内详';
$result=$result.'"vod_director":"'.$director.'",';
$result=$result.'"vod_content":"'.$adtitle2.'",';
$result= $result.'"vod_play_from":"'."无播放源".'",';
$result= $result.'"vod_play_url":"'."1".'"}]}';
echo $result;
}else{
//==============================================读取影视信息开始=======================================
$vid='https://pcweb.api.mgtv.com/video/info?vid='.$ids.'&_support=10000000';
$html = curl_get($vid,$cookie,$UserAgent);
$arr=json_decode($html,true);
$text=$arr['data']['info']['clipName'];
$img=$arr['data']['info']['clipImage'];
if (substr($img,0,2)=='//'){
$img = 'https:'.$img;
}
if($img==null){
$img= $historyimg;
}
$type =$arr['data']['info']['fstlvlType'];
$actor=$arr['data']['info']['detail']['leader']; 
$director=$arr['data']['info']['detail']['director']; 
$area=$arr['data']['info']['detail']['area']; 
$vodtext2=$arr['data']['info']['detail']['story']; 
$year=$arr['data']['info']['detail']['releaseTime']; 


$html ='';
$webids='https://pcweb.api.mgtv.com/episode/list?_support=10000000&version=5.5.35&video_id='.$ids.'&page=1&size=50';
for ($i = 0; $i < 3; $i++) {
$html = curl_get($webids,$cookie,$UserAgent);
if($html<>null){
break;
}
}



$arr=json_decode($html,true);
$arr_q1a=$arr['data']['list'];

$result='{"list":[{"vod_id":"'.$ids.'",';
if($text==null){
$text='片名获取失败';
}
$result=$result.'"vod_name":"'.$text.'",';
if($img<>null){
$result=$result.'"vod_pic":"'.$img.'",';
}
if($type<>null){
$result=$result.'"type_name":"'.$type.'",';
}
if($year<>null){
$result=$result.'"vod_year":"'.$year.'",';
}
if($actor==null){
$actor='内详';
}
$result=$result.'"vod_actor":"'.$actor.'",';
if($director==null){
$director='内详';
}
$result=$result.'"vod_director":"'.$director.'",';
if($area<>null){
$result=$result.'"vod_area":"'.$area.'",';
}
if($vodtext2<>null){
$vodtext2=str_replace('"','\"',$vodtext2);
$result=$result.'"vod_content":"'.$vodtext2.'",';
}
$m=count($arr_q1a);
$total=$arr['data']['total'];
$yuan = 'mgtv';
if($m=='0'){
$result= $result.'"vod_play_from":"'."mgtv".'",';
$result= $result.'"vod_play_url":"'.'高清$'.$ids.'"}]}';
}else{
for($i=0;$i<$m;$i++) 
{ 
$name=$arr['data']['list'][$i]['t4'];
$font=$arr['data']['list'][$i]['corner'][0]['font'];
if($font=='预'){
$name=$name.'(预告)';
}else if($font=='VIP'){
$name=$name.'(VIP)';
}
$t1=$arr['data']['list'][$i]['t1'];
$dizhi2='https://www.mgtv.com'.$arr['data']['list'][$i]['url'];
if(strpos($t1,'彩蛋')===false){
$dizhi=$dizhi.$name.'$'.$dizhi2.'#';
}
}

if($total>50){
$pg=floor($total/50);
for($i2=0;$i2<$pg;$i2++) {
$i3=$i2+2;
$ids2=str_replace('page=1','page='.$i3,$webids);
$html2 = curl_get($ids2,$cookie,$UserAgent);
$arr2=json_decode($html2,true);
$arr_q1a2=$arr2['data']['list'];
$m2=count($arr_q1a2);
for($i4=0;$i4<$m2;$i4++) 
{ 
$name=$arr2['data']['list'][$i4]['t4'];
$t1=$arr2['data']['list'][$i4]['t1'];
$font=$arr2['data']['list'][$i4]['corner'][0]['font'];
if($font=='预'){
$name=$name.'(预告)';
}else if($font=='VIP'){
$name=$name.'(VIP)';
}
$dizhi2='https://www.mgtv.com'.$arr2['data']['list'][$i4]['url'];
if(strpos($t1,'彩蛋')===false){
$dizhi=$dizhi.$name.'$'.$dizhi2.'#';
}
}
}
}
}
$dizhi=substr($dizhi, 0, strlen($dizhi)-1);
$dizhi2='';
$hello=explode("#",$dizhi);
if(count($hello)==2){
if(floor($hello[0])<floor($hello[1])){
$dizhi2=$hello[1].'#'.$hello[0];
$dizhi=$dizhi2;
}
}

$result= $result.'"vod_play_from":"'.$yuan.'",';
$result= $result.'"vod_play_url":"'.$dizhi.'"}]}';
}
echo $result;
//==============================================读取影视信息结束=======================================
}else  if ($burl<> null){

//=============================以下是直链分析代码=======================================================
$html = curl_get($burl,$cookie,$UserAgent);
$content=getSubstr($html,'var player','</script>');
$content=getSubstr($content,'"url":"','",');
$content=urldecode(str_replace("\/","/",$content));
if(strpos($content,'.m3u8')>0 or strpos($content,'.mp4')>0){
echo  '<iframe src="'.$content.'" class="iframeStyle" id="myiframe" ></iframe>';
}else{
$from=getSubstr($html,'"from":"','",');
$from=urldecode(str_replace("\/","/",$from));
$playerconfig=$web.'/static/js/playerconfig.js';
$playerhtml = curl_get($playerconfig,$cookie,$UserAgent);
if(strpos($playerhtml,'player_list=')>0){
$content2=getSubstr($playerhtml,'player_list=',',Mac');
$arr=json_decode($content2,true);
$show=$arr[$from]['show'];
$parse=$arr[$from]['parse'];
if (substr($parse,0,4)<>'http'){
$parse=$web.$parse;
}
$parse=str_replace("\/","/",$parse);
echo  '<iframe src="'.$parse.$content.'" class="iframeStyle" id="myiframe" ></iframe>';
}else{
echo  '<iframe src="'.$burl.'" class="iframeStyle" id="myiframe" ></iframe>';
}
}
//==============================以上是直链分析代码=======================================================



}else  if ($wd<> null){
//=============================以下是搜索代码=======================================================
if($searchable==0){
echo 'php未开启搜索';
exit;
}
if($page==null){
$page=1;
}
$key=urlencode($wd);
$search='https://mobileso.bz.mgtv.com/pc/search/v1?q={wd}&pn=1&pc=10&uid=';
$geturl =str_replace("{wd}",$key,$search);
$html = curl_get($geturl,$cookie,$UserAgent);
$arr=json_decode($html,true);
$arr_q1a=$arr['data']['contents'];
$m=count($arr_q1a);
$result='{"code":1,"page":'.$page.',"pagecount":'. $page.',"total":'. $m.',"list":[';
 for($i=0;$i<$m;$i++){
 $title = $arr_q1a[$i]['data']['title'];
 $link =  $arr_q1a[$i]['data']['vid'];
 if( $link==null){
$link =  $arr_q1a[$i]['data']['sourceList'][0]['vid'];
}

if($title<>null && $link<>null && strpos($title,"《")===false && strpos($title,$wd)<>false){
$result=$result.'{"vod_id":"'.$link.'","vod_name":"'.$title.'"},';
}


}
$result=substr($result, 0, strlen($result)-1).']}';
echo $result;
//==============================以上是搜索代码=======================================================
}else{
if($indexable==0){
echo $movietype;
}else{
$html = curl_get('https://pianku.api.mgtv.com/rider/list/pcweb/v3?platform=pcweb&channelId=2&pn=1&pc=80&hudong=1&_support=10000000&kind=a1&area=a1&year=all&edition=all&feature=all&chargeInfo=a1&sort=c1',$cookie,$UserAgent);
$arr=json_decode($html,true);
$arr_q1a=$arr['data']['hitDocs'];
$m=count($arr_q1a);
$guolv='';
$m2=0;
if($m==0){
echo $movietype;
}else{
$result=',"list": [';
for ($i = 0; $i < $m; $i++) {
$text=$arr['data']['hitDocs'][$i]['updateInfo'];

if($text==null){
$text=$arr['data']['hitDocs'][$i]['rightCorner']['text'];
}

$clipId=$arr['data']['hitDocs'][$i]['clipId'];
$playPartId=$arr['data']['hitDocs'][$i]['playPartId'];
$link =$playPartId;
$title =$arr['data']['hitDocs'][$i]['title'];
$pic = $arr['data']['hitDocs'][$i]['img'];

   if (substr($pic,0,2)=='//'){
	$pic = 'https:'.$pic;
	}
	
	if($title<>null && $link<>null){
if($guolv==null){
	    $result=$result.'{"vod_id":"'.$link.'","vod_name":"'.$title.'","vod_pic":"'.$pic.'","vod_remarks":"'.$text.'"},';
    	$guolv=$guolv."{".$link."}";
    	$m2=$m2+1;
}else if(strpos($guolv, "{".$link."}")===false){
	    $result=$result.'{"vod_id":"'.$link.'","vod_name":"'.$title.'","vod_pic":"'.$pic.'","vod_remarks":"'.$text.'"},';
    	$guolv=$guolv."{".$link2."}";
    	$m2=$m2+1;
	}
	}
	
	
	
	
		if($m2>=$indexnum){
	break;
	}
}
$result=substr($result, 0, strlen($result)-1).']}';
echo substr($movietype, 0, strlen($movietype)-1).$result;
}
}
}


function curl_get($url,$cookie2,$UserAgent2){
  $header = array(
       'Accept: */*',
       'Accept-Language: zh-cn',
       'Referer: '.$url,
       'User-Agent: '.$UserAgent2,
       'Content-Type: application/x-www-form-urlencoded'
    );
        $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 20);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt ($curl, CURLOPT_HTTPHEADER , $header);
    curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent2);
    if($cookie2<>null){
    curl_setopt($curl, CURLOPT_COOKIE, $cookie2);
    }
    $data = curl_exec($curl);
    if (curl_error($curl)) {
        return "Error: ".curl_error($curl);
    } else {
	curl_close($curl);
		return $data;
	}
	}
    
function curl_post($url,$postdata,$cookie2,$UserAgent2){
  $header = array(
       'Accept: */*',
       'Accept-Language: zh-cn',
       'Referer: '.$url,
       'User-Agent: '.$UserAgent2,
       'Content-Type: application/x-www-form-urlencoded'
    );
        $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 20);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt ($curl, CURLOPT_HTTPHEADER , $header);
    curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent2);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    if($cookie2<>null){
    curl_setopt($curl, CURLOPT_COOKIE, $cookie2);
    }
    $data = curl_exec($curl);
    if (curl_error($curl)) {
        return "Error: ".curl_error($curl);
    } else {
	curl_close($curl);
		return $data;
	}
	}


function getSubstr($str, $leftStr, $rightStr) 
{
if($leftStr<>null && $rightStr<>null){
$left = strpos($str, $leftStr);
$right = strpos($str, $rightStr,$left+strlen($leftStr));
if($left < 0 or $right < $left){
return '';
}
return substr($str, $left + strlen($leftStr),$right-$left-strlen($leftStr));
}else{
$str2=$str;
if($leftStr<>null){
$str2=str_replace($leftStr,'',$str2);
}
if($rightStr<>null){
$str2=str_replace($rightStr,'',$str2);
}
return $str2;
}
}

function replacestr($str2){
$test2=$str2;
$test2=str_replace("	","",$test2);
$test2=str_replace(" ","",$test2);
$test2 = preg_replace('/\s*/', '', $test2);
return $test2;
}
?>