1)
?是最短匹配{0,1}的缩写形式.所以g?实际上是匹配空字符(0个g),虽然
匹配成立,但是空字符的长度为0,所以返回1.(在使用ereg函数的时候,匹配长度为0或者第三个参数$regs没有指定的时候返回值为1,参见www.php.net文档)2)Mitchell与Harper间有两个空格所以并没有匹配上,ereg返回值是false,打印false为空.
修改一下:
echo ereg("Mitchell[[:space:]]{2}Harper", "Mitchell  Harper")." <P>";
因为第三个参数$regs没有指定,所以输出为1<P>.
再修改一下:
ereg("Mitchell[[:space:]]{2}Harper", "Mitchell  Harper", $regs);
var_dump($regs);
可以看到输出结果为:
array(1) {
  [0]=>
  string(16) "Mitchell  Harper"
}

解决方案 »

  1.   

    嗯,说得不错
    echo ereg("Mitchell[[:space:]]?Harper", "Mitchell  Harper")." <P>";//Mitchell与Harper间有两个空格
    对于上面这行,我的理解是,int ereg ( string pattern, string string [, array &regs] )函数调用没有第三个参数reg,所以也应该返回1,是不是?
      

  2.   

    你加上第三个参数就知道了.
    即使有第三个参数,[[:space:]]?也无法匹配两个空格(只有0个或者1个空格),返回值是false,
    把?改成+就匹配了.
      

  3.   

    就是:如果既没有匹配上去,又没有传递第三个参数给函数,那么,函数返回值是FALSE还是1呢?谢谢
      

  4.   

    Returns the length of the matched string if a match for pattern was found in string, or FALSE if no matches were found or an error occurred. If the optional parameter regs was not passed or the length of the matched string is 0, this function returns 1. 说明手册上这一段感觉有点矛盾============
    好了,明白了,谢谢!
      

  5.   

    首先没匹配上返回false
    匹配上但是长度为0或者没有第三个参数返回1
    匹配上,有第三个参数返回匹配上的长度.