+ -
当前位置:首页 → 问答吧 → 正则的问题(| at [^\ ]+ Port [0-9]+|i)

正则的问题(| at [^\ ]+ Port [0-9]+|i)

时间:2011-09-24

来源:互联网

  1. $host = 'www.example.com';
  2. echo $_SERVER[(SERVER_SIGNATURE)];
  3. $_SERVER[(SERVER_SIGNATURE)] = preg_replace((| at [^\ ]+ Port [0-9]+|i), ( at ) . $host . ( Port ) . $port, $_SERVER[(SERVER_SIGNATURE)]);
  4. echo "The new is ---" . $_SERVER[(SERVER_SIGNATURE)];
复制代码
输出以后是
Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch Server at www.example.com Port 80
The new is ---Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch Server at www.example.com Port

请问PHP的正则 [^\ ] 可以匹配 www.example.com 吗? why?

作者: andis01   发布时间: 2011-09-24

“请问PHP的正则 [^\ ] 可以匹配 www.example.com 吗? why?”
可以!

测试也证明了:
  1. $host = 'www.example.com';
  2. $port = '';
  3. echo $_SERVER['SERVER_SIGNATURE'];
  4. $_SERVER['SERVER_SIGNATURE'] = preg_replace('/ at [^\ ]+ Port [0-9]+/i', 'at'.$host.'Port'.$port,$_SERVER['SERVER_SIGNATURE']);
  5. echo "The new is ---" . $_SERVER['SERVER_SIGNATURE'];
复制代码
输出:
<address>Apache/2.2.14 (Ubuntu) Server at localhost.com Port 80</address>
The new is ---<address>Apache/2.2.14 (Ubuntu) Serveratwww.example.comPort</address>

作者: ddm   发布时间: 2011-09-24

“请问PHP的正则 [^\ ] 可以匹配  吗? why?”
可以!

测试也证明了:输出:
Apache/2.2.14 (Ubuntu) Serve ...
ddm 发表于 2011-9-24 20:03



    测试我都测试了, 我就想问这是为什么呢?

作者: andis01   发布时间: 2011-09-24

  1. [^\ ]
复制代码
这是匹配除了空格以外的所有字符,你自己说可不可以!!
除非你不知道这个是什么意思

作者: ddm   发布时间: 2011-09-24