Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-正则表达式,以匹配以_Php_Regex - Fatal编程技术网

php-正则表达式,以匹配以

php-正则表达式,以匹配以,php,regex,Php,Regex,非常抱歉,阵列如下所示: Array ( [1] => Array ( [0] => msie6.0 [1] => 7 ) [2] => Array ( [0] => safari5.0.3 [1] => 5 ) [3] => Array ( [0] => chrome18.0.1025.308 [1] =&g

非常抱歉,阵列如下所示:

Array
(
[1] => Array
    (
        [0] => msie6.0
        [1] => 7
    )

[2] => Array
    (
        [0] => safari5.0.3
        [1] => 5
    )

[3] => Array
    (
        [0] => chrome18.0.1025.308
        [1] => 1
    )

[4] => Array
    (
        [0] => firefox20.0
        [1] => 4
    )
[5] => Array
    (
        [0] => msie7.0
        [1] => 915
    )
等等。。。 当我尝试用
InternetExplorer
替换例如
msie6.0
msie7.0
并添加它时:

preg_match("/#^msie(.*)$#i/is", $results, $matches);
$test = $matches[0] ;
print_array($test);
$results["#^startText(.*)$#i"] = $results['InternetExplorer'];
print_array($results);
unset($results["/#^msie(.*)$#i/is]);
它不符合我想要的完美。有什么解决办法吗? 为了:

Array
(
[1] => Array
    (
        [0] => InternetExplorer
        [1] => 922
    )

[2] => Array
    (
        [0] => safari5.0.3
        [1] => 5
    )

[3] => Array
    (
        [0] => chrome18.0.1025.308
        [1] => 1
    )

[4] => Array
    (
        [0] => firefox20.0
        [1] => 4
    )

在你在评论中澄清之后。我想你不需要正则表达式,那工作就足够了

$rows["InternetExplorer"] = 0;
foreach($rows as $key => $value){
  if(strpos($key,"msie") !== false){
     $rows["InternetExplorer"] += $value;
     unset($rows[$key]);
  }
}

你想用“InternetExplorer”或整键替换一个部分吗?我想替换以
msie
开头的每一个键,并将其值添加到
InternetExplorer
的所有值的总和中。对不起!我已经编辑了我的帖子!我希望它看起来像结果。你试过我的代码吗?检查演示链接?它会给你和你期望的一样的结果。