[Help] there is a need for regular expressions to obtain the JS array in a file, reading the JS array in a file capture file. This regular sentence can only capture one value & nbsp; Array \ (. +? \); And php does not only obtain the matching array, so we consider how to obtain the JS array in the file using & nbsp; preg_repl [help] regular expressions.
There is a requirement to read the JS array in a file capture file.
Only one value Array \ (. +? \);
In addition, php does not only obtain the matched array. Therefore, we should use the preg_replace method to replace all the data except the data that I want, and leave only what I need.
But I don't know how to implement it. please help me. Regular cropping File php array JS shared:
------ Solution --------------------
$ S = your string
Preg_match_all ('/Array \ (. + \)/sU', $ s, $ m );
Print_r ($ m );
------ Solution --------------------
$s =<<< TXT
var switchPara = new Array(26,0,1,24,25,2,6,8,2,2,4);
var VlanTagGlobalList = new Array(
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 1,
0, 1, 0,
0, 0, 99,
0, 0, 99,
0,0 );
var VlanTagGlobalTList = new Array(
0, 99,
0, 99,
0, 99,
0, 99,
0, 99,
0, 99,
0,0 );
var userLevel=window.parent.user[1];
//-->
TXT;
preg_match_all('/new Array\((.+?)\)/s', $s, $r);
print_r($r[1]);
Array
(
[0] =>, 4
[1] =>
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,