{#title#}{#con#}
想通过preg_match_all分别得到title、con这两个字符串,正则怎么写?

解决方案 »

  1.   


    $str = '{#title#}
    {#con#}';
    preg_match_all('/\{#([\w]+)#\}/', $str, $m);
    print_r($m[1]);
    /*
    Array
    (
        [0] => title
        [1] => con
    )
    */
      

  2.   


    <?php
    $str='{#title#}{#con#}';
    preg_match_all('/\{#(.*?)#\}/',$str,$result);
    //print_r($result);
    foreach($result[1] as $value){
    echo $value.'<br />' ;
    }
    ?>
      

  3.   


    $str = '{#title#}{#con#}';
    preg_match_all('/[\w]+/',$str,$out);
    print_r($out);
    会得到以下结果:
    array(1) {
      [0]=>
      array(2) {
        [0]=>
        string(5) "title"
        [1]=>
        string(3) "con"
      }
    }