做采集的时候用得上。
- /*
- 解析JS代码函数
- JS代码如:
- var pp_link="/videos/41939vod-play-id-41939-(ppvod).html";var pp_vodname="寒战";
- 解析输出:
- Array(
- [pp_link] => "/videos/41939vod-play-id-41939-(ppvod).html"
- [pp_vodname] => "寒战"
- )
-
- */
- function parse_js($string){
- $pregString="#var ([a-zA-Z_0-9]+)=([^;]*);#";
- preg_match_all($pregString,$string,$JsArrayPre);
- $num=count($JsArrayPre['0']);
- for($i=0;$i $jsVarName=$JsArrayPre['1'][$i];
- $JsArray[$jsVarName]= $JsArrayPre['2'][$i];
- }
- return $JsArray;
- }
复制代码
|