解决方案 »

  1.   

    header("Content-type: text/html; charset=utf-8");
    $regex = '/大(.*?)好啊/';
    $str = '大家好啊';
    $matches = array();
      
    if(preg_match($regex, $str, $matches)){
        var_dump($matches);
    //array(2) { [0]=> string(12) "大家好啊" [1]=> string(3) "家" }
    }
      

  2.   

    如果我str里面还有字母,得用gb2312格式的该如何去写?
      

  3.   

    有什么区别吗?$regex = '/大(.*?)好啊/';
    $str = '大家好啊';
    $matches = array();
       
    if(preg_match($regex, $str, $matches)){
        var_dump($matches);
    }array(2) { [0]=> string(8) "大家好啊" [1]=> string(2) "家" } 
      

  4.   

    会乱码。$str = 'a大家好啊';$regex = '/a大(.*?)好啊/';
      

  5.   


    header("Content-type: text/html; charset=gb2312"); 
    $regex = '/大(.*?)好啊/';
    $str = '大家好啊';
    $str= mb_convert_encoding($str,'gb2312','UTF-8');
    $regex = mb_convert_encoding($regex,'gb2312','UTF-8');;
    $matches = array();
       
    if(preg_match($regex, $str, $matches)){
        var_dump($matches);
    //array(2) { [0]=> string(12) "大家好啊" [1]=> string(3) "家" }
    }
      

  6.   

    怎么可能?$regex = '/a大(.*?)好啊/';
    $str = 'a大家好啊';
    $matches = array();
        
    if(preg_match($regex, $str, $matches)){
        var_dump($matches);
    }array(2) { [0]=> string(9) "a大家好啊" [1]=> string(2) "家" }