用正则表达式把str中匹配的各项放到数组中。

解决方案 »

  1.   

    $reg = "/&(str[0-9])=([0-9])/U";
    preg_match_all($res, $str, $out);
    array_combine($out[1], $out[2]);
      

  2.   

    <?php
    $str="&str1=1&str2=2&str3=3";
    preg_match_all("|&([\w]+)=([\w])|",$str,$match,PREG_PATTERN_ORDER);
    $num=count($match[0]);
    for($i=0;$i<$num;$i++)
    {
    $mat_key=$match[1][$i];
    $mat_val=$match[2][$i];
    $arr[$mat_key]=$mat_val;
    }
    print_r($arr);
    ?>
      

  3.   

    http://www.52its.com/article/docslist.htm
    在这里找正则表达式相关的内容
      

  4.   

    <?php
    $str = "&str1=1&str2=2&str3=3";
    $ptr = "/([^&=]+)=([^&=]*)/";
    preg_match_all($ptr,$str,$result,PREG_SET_ORDER);
    for ($i=0;$i<count($result);$i++) {
    echo "键:".$result[$i][1]."<br>";
    echo "值:".$result[$i][2]."<hr>";
    }
    ?>