-1

Recently I saw a problem in a simple code:

$regexp = "^((http://)|(https://)|(mailto:)|(ftp://))?(([a-zA-Z0-9_.!~*'()-]|(%[0-9a-fA-F]{2})|[;&=+$,])+(:([a-zA-Z0-9_.!~*'()-]|(%[0-9a-fA-F]{2})|[;:&=+$,])+){0}@){0}((((((2(([0-4][0-9])|(5[0-5])))|([01]?[0-9]?[0-9]))\.){3}((2(([0-4][0-9])|(5[0-5])))|([01]?[0-9]?[0-9]))))|(([a-zA-Z0-9](([a-zA-Z0-9-]{0,62})[a-zA-Z0-9])?\.)*([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)))?(:(([0-5]?[0-9]{1,4})|(6[0-4][0-9]{3})|(65[0-4][0-9]{2})|(655[0-2][0-9])|(6553[0-5])))?(/((;)?([a-zA-Z0-9_.!~*'()-]|(%[0-9a-fA-F]{2})|[:@&=+$,])+(/)?)*)?(\?([;/?:@&=+$,]|[a-zA-Z0-9_.!~*'()-]|(%[0-9a-fA-F]{2}))*)?(#([;/?:@&=+$,]|[a-zA-Z0-9_.!~*'()-]|(%[0-9a-fA-F]{2}))*)?$";
$urladdr = '89.221.92.122/api/xml';
$result = eregi($regexp, $urladdr);

wamp server returns true, while xampp server returns false! I know that eregi is deprecated, but right know I expect it to work fine in php 5.3.1

My Question

Is there any php or apache config caused this behavior?

A simple test file of the script is uploaded here: eregi on xampp + phpinfo
The above code in my wamp is here: eregi on wamp + phpinfo

I don't want you to solve my problem, I just want to know why this kind of problems happen.

4

2 回答 2

3

It appears that the POSIX "extended regex" module/extension can either take advantage of native system support or use an implementation bundled with the PHP source. I haven't found any clear reference to this, but there are clues:

  • In the extension's "Installation" instructions, an option is described for which of 3 implementations to compile in. I note that one of the options is "apache", implying that even under Windows, a "third-party" implementation might be available.
  • You can browse the source code for where the implementations are actually loaded, e.g. the series of if statements in ext/ereg/php_regex.h
  • The phpinfo() output you posted includes the line "Bundled library enabled". (Incidentally, I came upon the source which outputs that: ext/ereg/ereg.c line 238.

This is actually quite common for many of the older parts of PHP, which were originally built on system libraries and APIs which can reliably be found on "POSIX-compliant" systems, and were later "ported" to other systems by reimplementing the required functionality. This causes some discrepancies between platforms, particularly on Windows, where most of the expected libraries will be missing.

Recent versions of PHP have tried to identify and rectify such inconsistencies - for instance, many of the filesystem-related functions used to have warnings of limited or incorrect behaviour under Windows, but now show these as fixed in a particular version. However, since this particular extension has been deprecated in favour of the cross-platform PCRE library, there has probably not been a great deal of testing of its different implementations, even before the official deprecation notice was added in PHP 5.3.

于 2013-07-25T21:55:44.460 回答
1

eregi is deprecated! Use preg instead.

See: How can I convert ereg expressions to preg in PHP?

于 2013-07-25T20:22:15.307 回答