# php5-pcre utf-8 problems



## saiman (Nov 29, 2008)

Hi all,
I'm trying to get php5-pcre working with utf-8 support. Here is the test case:

<?php
if (@preg_match('/\pL/u', 'a') == 1) {
    echo "PCRE unicode support is turned on.\n";
} else {
    echo "PCRE unicode support is turned off.\n";
}
?>

And the result is "PCRE unicode support is turned off". I have the following installed:

# pkg_info |grep pcre
pcre-7.8            Perl Compatible Regular Expressions library
php5-pcre-5.2.6_2   The pcre shared extension for php

And this is the output from pcretest -C:

PCRE version 7.8 2008-09-05
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

I'm using FreeBSD 6 stable. This is the output from uname:

FreeBSD xxxx 6.3-STABLE FreeBSD 6.3-STABLE #2: Mon Aug  4 16:50:44 EEST 2008

I tried to reinstall pcre and php5-pcre, but the result is the same. Any suggestions are welcome. 

Tanks in advance !


----------



## aragon (Nov 30, 2008)

I think your test case should be:

if (@preg_match('/\p{L}/u', 'a') == 1) {


----------



## saiman (Nov 30, 2008)

The test case is changed, but the result is still:

"PCRE unicode support is turned off."


----------



## aragon (Nov 30, 2008)

That is strange.  Did you install from ports?  Mine works:


```
$ php -q
<?
if (@preg_match('/\p{L}/u', 'a') == 1) {
echo "PCRE unicode support is turned on.\n";
} else {
echo "PCRE unicode support is turned off.\n";
}
?> 
PCRE unicode support is turned on.

$ pkg_info -xI php
php5-5.2.6          PHP Scripting Language
php5-ctype-5.2.6    The ctype shared extension for php
php5-dom-5.2.6      The dom shared extension for php
php5-gettext-5.2.6_1 The gettext shared extension for php
php5-mbstring-5.2.6 The mbstring shared extension for php
php5-mhash-5.2.6    The mhash shared extension for php
php5-mysql-5.2.6    The mysql shared extension for php
php5-openssl-5.2.6_2 The openssl shared extension for php
php5-pcre-5.2.6     The pcre shared extension for php
php5-pdo-5.2.6      The pdo shared extension for php
php5-pdo_mysql-5.2.6 The pdo_mysql shared extension for php
php5-pdo_sqlite-5.2.6_1 The pdo_sqlite shared extension for php
php5-session-5.2.6  The session shared extension for php
php5-simplexml-5.2.6 The simplexml shared extension for php
php5-spl-5.2.6      The spl shared extension for php
php5-wddx-5.2.6     The wddx shared extension for php
php5-xml-5.2.6      The xml shared extension for php
php5-xmlreader-5.2.6_1 The xmlreader shared extension for php
php5-xmlrpc-5.2.6_2 The xmlrpc shared extension for php
php5-xsl-5.2.6      The xsl shared extension for php
php5-zlib-5.2.6     The zlib shared extension for php
```


----------



## saiman (Dec 2, 2008)

> Did you install from ports?



Yes. I used ports.


----------



## kamikaze (Dec 2, 2008)

Maybe you have to set a locale with UTF-8.


----------



## saiman (Dec 2, 2008)

I modified /etc/login.conf inserting the following line in default section:


```
:charset=UTF-8:\
```

Then rebuild with:


```
cap_mkdb /etc/login.conf
```

After that i recompiled the php with:


```
portupgrade -Df php5*
```

And the result is still the same:


```
# php test.php 
PCRE unicode support is turned off.
```


----------



## aragon (Dec 2, 2008)

Try install the pcre module from a package build.


----------



## saiman (Dec 2, 2008)

Obviously the problem it's not into the port, because with the package the result is the same. It's something else ..


----------



## Mel_Flynn (Dec 3, 2008)

Could you show:

```
make -C /usr/ports/lang/php5 showconfig
```


----------



## saiman (Dec 3, 2008)

```
# make -C /usr/ports/lang/php5 showconfig
===> The following configuration options are available for php5-5.2.6_2:
     CLI=on "Build CLI version"
     CGI=off "Build CGI version"
     APACHE=on "Build Apache module"
     DEBUG=off "Enable debug"
     SUHOSIN=on "Enable Suhosin protection system (not for jails)"
     MULTIBYTE=on "Enable zend multibyte support"
     IPV6=off "Enable ipv6 support"
     MAILHEAD=on "Enable mail header patch"
     REDIRECT=off "Enable force-cgi-redirect support (CGI only)"
     DISCARD=off "Enable discard-path support (CGI only)"
     FASTCGI=on "Enable fastcgi support (CGI only)"
     PATHINFO=on "Enable path-info-check support (CGI only)"
===> Use 'make config' to modify these settings
```


----------



## dave (Dec 4, 2008)

Perhaps this is a silly question - but... (if you are using mod_php5) did you restart apache after rebuilding PCRE extension?


----------



## Mel_Flynn (Dec 4, 2008)

Well, the usual suspect, multibyte zend is on. Next up: mbstring extension is loaded? And the internal encoding:

```
php -i |grep internal_encoding
```


----------



## saiman (Dec 4, 2008)

> did you restart apache after rebuilding PCRE extension?



Yes I did.


```
php -i |grep internal_encoding
iconv.internal_encoding => ISO-8859-1 => ISO-8859-1
mbstring.internal_encoding => ISO-8859-1 => no value
```


----------



## wuciwug (Nov 4, 2011)

*Solved (for me at least!)*

I know its old - Google doesn't care though! Try running your test script on the command line i.e `php xxx.php` and see if that works. I found with apache-2.2.21 and php5-5.3.8 I needed to add 
	
	



```
AddDefaultCharset utf8 to httpd.conf
```
 to httpd.conf.


----------

