4

I have a weird problem. consider this short code:

<?php
$reg =  '/(?<!\pL)(test)(?!\pL)/u';
$text='This is a test text';
$replace = 'test_replaced';

$newtext = preg_replace($reg, $replace, $text);

echo "Error: ".preg_last_error()."\nResult: ".$newtext."\n";

?>

On some servers the UTF8 boundary matching does not work. I get

Error: 0
Result: 

On majority servers everything works normally:

Error: 0
Result: This is a test_replaced text

There seems to be a problem with word boundary as when I use \b instead the code works.

Both servers use php 5.2.13. Any clues what might be wrong and how to get around it?

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
freediver
  • 309
  • 1
  • 10

1 Answers1

3

Comment here seems to suggest that PCRE needs to be compiled with --enable-unicode-properties.

SilentGhost
  • 307,395
  • 66
  • 306
  • 293