note 94424 added to function.preg-match

From: 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

« previous php.notes (#162384) next »