note 94424 added to function.preg-match
| From: | ruakuu at NOSPAM dot com | Date: | Wed, 04 Nov 2009 05:32:29 +0000 |
| Subject: | note 94424 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162384@lists.php.net to get a copy of this message | ||
Was working on a site that needed japanese and alphabetic letters and needed to
validate input using preg_match, I tried using \p{script} but didn't work:
<?php
$pattern ='/^([-a-zA-Z0-9_\p{Katakana}\p{Hiragana}\p{Han}]*)$/u'; // Didn't work
?>
So I tried with ranges and it worked:
<?php
$pattern ='/^[-a-zA-Z0-9_\x{30A0}-\x{30FF}'
.'\x{3040}-\x{309F}\x{4E00}-\x{9FBF}\s]*$/u';
$match_string = 'å°å·æå® ãããè·¡é¤å»
ã²ã¼ã ãã¼ã¤';
if (preg_match($pattern, $match_string)) {
echo "Found - pattern $pattern";
} else {
echo "Not found - pattern $pattern";
}
?>
U+4E00âU+9FBF Kanji
U+3040âU+309F Hiragana
U+30A0âU+30FF Katakana
Hope its useful, it took me several hours to figure it out.
----
Server IP: 69.147.83.197
Probable Submitter: 201.151.146.39
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/94424
Del: integrated -- https://master.php.net/note/delete/94424/integrated
Del: useless -- https://master.php.net/note/delete/94424/useless
Del: bad code -- https://master.php.net/note/delete/94424/bad+code
Del: spam -- https://master.php.net/note/delete/94424/spam
Del: non-english -- https://master.php.net/note/delete/94424/non-english
Del: in docs -- https://master.php.net/note/delete/94424/in+docs
Del: other reasons-- https://master.php.net/note/delete/94424
Reject -- https://master.php.net/note/reject/94424
Search -- https://master.php.net/manage/user-notes.php