Parse JS code function (parse JS variables into PHP arrays)

WBOY
Release: 2016-07-25 09:01:26
Original
1502 people have browsed it

Useful when collecting.

  1. /*
  2. Parse JS code function
  3. JS code such as:
  4. var pp_link="/videos/41939vod-play-id-41939-(ppvod).html";var pp_vodname="chill";
  5. Parse output:
  6. Array(
  7. [pp_link] => "/videos/41939vod-play-id-41939-(ppvod).html"
  8. [pp_vodname] => "Chill"
  9. )
  10. */
  11. function parse_js($string ){
  12. $pregString="#var ([a-zA-Z_0-9]+)=([^;]*);#";
  13. preg_match_all($pregString,$string,$JsArrayPre);
  14. $num= count($JsArrayPre['0']);
  15. for($i=0;$i<$num;$i++){
  16. $jsVarName=$JsArrayPre['1'][$i];
  17. $JsArray[$ jsVarName]= $JsArrayPre['2'][$i];
  18. }
  19. return $JsArray;
  20. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!