Dave
Dave

Reputation: 12487

PHP regex behaves differently on different versions or different OS's

I'm using two different version of php on two different OS's.

One is 5.2.9 running on windows (wamp).

One is 5.2.6 running on CentOS 5 (lamp).

Regex involving group names works on the Windows one but not on the CentOS.

Such example would be /^field_(?<myname>.+)/

Is this an OS issue? Or one with the way PHP was build?

Thanks,

Upvotes: 1

Views: 230

Answers (2)

user38736
user38736

Reputation: 66

Most regex functions available in PHP derive back to libpcre, that library has had a turbulent history in the couple years in response to some security issues, the fixes for those issues change semantics. When building PHP by default it uses a bundled libpcre, when that changes it is noted in the changelog here: http://www.php.net/ChangeLog-5.php . Some distributions or if you compile yourself may cause php to use an external libpcre which will have the semantics of that version.

There is no good solution except that so far things tend to break forward, meaning if your regex works with the latest version it tends to work inl historical versions, the reverse, as I pointed out, is not true.

Upvotes: 2

Marius
Marius

Reputation: 58959

Which regex functions do you use? PHP has ereg and preg, and the preg regular expression behaves like perls regular expression, and should behave the same on all OSes.

Upvotes: 0

Related Questions