假如一文件中有包含以下$actionMaps = array(
................,
................,
);字符串,如何把该字符串匹配出来~``

解决方案 »

  1.   

    <?php
    $subject = file_get_contents('yourfilename');
    preg_match_all('/\$actionMaps = array\(.*\);/is', $subject, $matches);
    print_r($matches);
    ?>
      

  2.   

    代码最好多一些,这种方法,数组中间如果内容如果有字符串);就完蛋了
    如果字符串符合php语法,可以考虑include这个文件,然后将数组打印出来
    $str = 'asdfas^……
    $actionMaps = array(
    ................,
    ................,
    );
    ^!@#@!#!
    ';
    echo preg_match_all('/\$actionMaps = array\((.*?)\);/is', $str, $match);print_r($match[0]);
      

  3.   


    $str='
    $a="432435";
    $actionMaps = array(
    0=>array(
    0=>"123",
    "a"=>"abc",
    ),
    1=>array(
    0=>"123",
    "a"=>"abc",
    ),
    );
    //gfdgfdgdfgd
    $actionMaps1 = array(
    0=>"123",
    "a"=>"abc",
    );
    $fsfs=54353;
    //543535
    ';
    preg_match_all('~(\$[a-zA-z0-9_]+\s?=\s?array\([^;]*?\);)~is',$str,$data);
    print_r($data[0]);
      

  4.   


    $str = '
    $actionMaps = array(
    ................,
    ................,
    );
    ';preg_match('/\$actionmaps.*?\);/is', $str, $match);print_r($match);
      

  5.   


    $actionMaps = array('list' => 'ListAction',
    'view' => 'ViewAction',
    ...,);
    相当于就是把array里面的数据提取出来~`