my aim
for the "author name input", to be sure that only spaces and utf-8 letters are inputted. my website lang is Turkish, Turkish alphabet has non-English characters.
my weird issue
this regex works on rubular.com
if input string : "Selim Çınar" result : matches
if input string : "Selim Çınar 12" result : don't match
regex: /^[\p{L} ]+$/u
then I created trial.php on my website and run codes below
1
echo '<br /><br /><br />';
$str ='Selim Cinar';
if (!preg_match("/^[\p{L} ]+$/u", $str))
{echo 'no, not only utf-8 letters and spaces';}
else {$str.' yes utf-8 letters and spaces';}
echo '<br /><br /><br />';
result for code above : empty page with only <br />
tags at source page
2
echo '<br /><br /><br />';
$str ='Selim Çınar'; //includes Tr characters
if (!preg_match("/^[\p{L} ]+$/u", $str))
{echo 'no, not only utf-8 letters and spaces';}
else {$str.' yes utf-8 letters and spaces';}
echo '<br /><br /><br />';
result for code above : empty page with only <br />
tags at source page
3
code source: http://php.net/manual/en/function.ctype-alpha.php
$str ='Selim Çınar'; //includes Tr characters
$str =trim($str);
$str = str_replace(' ', '', $str);
setLocale(LC_CTYPE, 'TR_tr.UTF-8');
if (ctype_alpha($str)) {echo 'yes utf-8 letters';}
else {echo 'no, not only utf-8 letters';}
result for code above : no, not only utf-8 letters
4
code source: http://php.net/manual/en/function.ctype-alpha.php
$str ='Selim Cinar';
$str =trim($str);
$str = str_replace(' ', '', $str);
setLocale(LC_CTYPE, 'TR_tr.UTF-8');
if (ctype_alpha($str)) {echo 'yes utf-8 letters';}
else {echo 'no, not only utf-8 letters';}
result for code above : yes utf-8 letters
my phpinfo
PHP Version 5.4.10
Apache 2.0 Handler
Apache API version: 20051115
PCRE (Perl Compatible Regular Expressions) Support enabled
PCRE Library Version 8.20 2011-10-21
about trial.php
trial.php is pure php. no html header declaration.
My Questions
- why am I getting empty page for case 1 and case 2 {! UPDATE : SOLVED by MikeM below }
- Why case 3 doesn't understand "SelimÇınar" as utf-8? Is my code
false (
setLocale
part maybe)?
UPDATE
question 1 is solved by MikeM.
**question 2 still exists as an question.