[求助]正则如何获取文件中的JS数组
用该正则句仅能抓取到一个值 Array\(.+?\);
而且php中没有仅获取匹配后的数组,所以考虑用 preg_replace 方法将除我想要的数据之外其他数据全部替换掉,最后仅留我需要的部分。
但不知道怎么实现,麻烦大家帮忙咯。
回复讨论(解决方案)
贴出你文件中的数据看看
截掉了部分,要不发不了
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];
//--></Script>
<body><center>
<form action="/userRpm/VlanTagGlobalAd.htm" enctype="multipart/form-data" method="get">
<table class="tphead" width="500" cellspacing=0 cellpadding=0>
<tr><td >Tag VLAN全局配置</td></tr>
</table>
<TABLE class=tpbody cellspacing=0 cellpadding=0 width="500">
<TR><TD align="center"><table width="400" class=tpbodyin>
<TR><TD ><table class=plist>
<tr class=plisttop> <td>端口</td><td>缺省VID</td><td>Untag帧处理 </td><td>端口</td><td>缺省VID</td><td>Untag帧处理 </td></tr>
<script language="JavaScript"><!--
for(i=1;i<=switchPara[0];i=i+2)
{ if(((i+1)/2)%2==1)document.write('<tr>');
else document.write('<tr class=plistsep>');
for(j=i;j<i+2;j++)
{ if(j>switchPara[0])
break;
document.write( '<td>'+shiftp(j)+'</td><td><input TYPE=text class=\"text\" SIZE=4 maxlength=4 name=vid></td><td><select name=inr style=\'width:50\'><option value="0" >通过</option><option value="1">丢弃</option>');
if(VlanTagGlobalList[(j-1)*3+2]==99)
document.write('<option value="99" >--</option>');
document.write('</select></td>');
}
document.write('</tr>');
}
if(userLevel == 1)
{
for(var k = 0; k <= switchPara[0] * 2 - 1; k++)
{
document.forms[0].elements[k].disabled = true;
}
}
var temptrunk;
document.write('<tr></tr><tr></tr>');
for(i=1;i<=switchPara[6];i=i+2)
{if(((i+1)/2)%2==1)document.write('<tr class=plistsep>');
else document.write('<tr>');
for(j=i;j<i+2;j++)
{ temptrunk="T"+j;
if(j>switchPara[6])
break;
else
document.write( '<td>'+temptrunk+'</td><td><input TYPE=text class=\"text\" SIZE=4 maxlength=4 name=vidT></td><td><select name=inrT style=\'width:50\'><option value="0" >通过</option><option value="1">丢弃</option>');
if(VlanTagGlobalTList[(j-1)*2+1]==99)
document.write('<option value="99" >--</option>');
document.write('</select></td>');
}
document.write('</tr>');
}
if(userLevel == 1)
{
for(k = switchPara[0]*2 ; k <= switchPara[0]*2 + switchPara[6]*2 - 1; k++)
{
document.forms[0].elements[k].disabled = true;
}
}
//--></Script>
<tr><td style='height:10'></td></tr>
<tr>
<td colspan="2"><div align="left">所有端口</div></td>
<td><select name=inrAll style='width:50'onChange="changeinr();">
<option value="99" >--</option>
<option value="0" >通过</option>
<option value="1">丢弃</option>
</select></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</td></tr></table>
</td></tr>
</table>
<table class=tptail cellspacing=0 cellpadding=0 width="500">
<tr><td><INPUT name=submit type=submit class=bbtn value="提交" onClick="return doSubmit();">
<INPUT name=help type=button class="bbtn" value="帮助" onClick="doHelp('VlanTagGlobalHelp.htm');" >
</td></tr></table>
<script language="JavaScript"><!--
if(switchPara[0]%2==0)
index = switchPara[0]/2;
else
index = (switchPara[0]+1)/2;
if(switchPara[6]%2==0)
indexT = switchPara[6]/2;
else
indexT = (switchPara[6]+1)/2;
for(i=1;i<=index;i++)
{document.write('<input name="p'+i+'" type="hidden">');}
for(i=1;i<=indexT;i++)
{document.write('<input name="t'+i+'" type="hidden">');}
//--></Script>
</form></center></body><head><meta http-equiv="pragma" content="no-cache"></head></html>
<script language="JavaScript"><!--
var DF = document.forms[0];
for( i=1;i<=switchPara[0];i++)
{
betrunk=VlanTagGlobalList[(i-1)*3];
if(betrunk!=0)
{
DF.vid[i-1].value=VlanTagGlobalTList[(betrunk-1)*2];
DF.vid[i-1].disabled=true;
DF.inr[i-1].value=VlanTagGlobalTList[(betrunk-1)*2+1];
DF.inr[i-1].disabled=true;
}
else //betrunk==0 or portdisabled
{
DF.vid[i-1].value =VlanTagGlobalList[(i-1)*3+1];
DF.inr[i-1].value =VlanTagGlobalList[(i-1)*3+2];
if(DF.inr[i-1].value==99)
{
DF.vid[i-1].disabled = true;
DF.inr[i-1].disabled = true;
}
}
}
for( i=1;i<=switchPara[6];i++)
{
if(VlanTagGlobalTList[(i-1)*2+1]==99)
{
DF.vidT[i-1].disabled=true;
DF.inrT[i-1].disabled=true;
}
DF.vidT[i-1].value = VlanTagGlobalTList[(i-1)*2];
DF.inrT[i-1].value = VlanTagGlobalTList[(i-1)*2+1];
}
//--></Script>
<script language = "JavaScript" type = "text/javascript"><!--
if(userLevel == 1)
{
document.forms[0].submit.style.display = "none";
}
//--></script>
$s=你的串preg_match_all('/Array\(.+\)/sU',$s,$m);print_r($m);
$s =TXT;preg_match_all('/new Array\((.+?)\)/s', $s, $r);print_r($r[1]);Array
(
[0] => 26,0,1,24,25,2,6,8,2,2,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,
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
[2] =>
0, 99,
0, 99,
0, 99,
0, 99,
0, 99,
0, 99,
0,0
)
谢谢,十分的感谢。
还是自己的基本不扎实,我还一直以为没有这类函数呢。
看到preg_match_all 仅看到了返回值是int 我就直接放弃看它了。。。
再次感谢
下一篇: PHP笔记(CSS篇)