how to add Arabic letters to url regex

2020-02-15 07:33发布

how to add Arabic letters to url in regex

if (!preg_match("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$^",$_POST['url'])) {}

3条回答
何必那么认真
2楼-- · 2020-02-15 08:06

Replace [a-zA-Z0-9] with [\pL0-9] and don't forget the the Unicode PCRE modifier /u at the end of your regex.

查看更多
乱世女痞
3楼-- · 2020-02-15 08:16

Using its UTF-8 code: \x123 should help.

UPD: the full regexp seems to be like this (for the rule any URL part could contain arabic chars):

^(http|https|ftp)\://[a-zA-Z0-9\-\.\x0600-\x06FF\x0750-\x077F\xFB50-\xFDFF\xFE70-\xFEFF]+\.[a-zA-Z\x0600-\x06FF\x0750-\x077F\xFB50-\xFDFF\xFE70-\xFEFF]{2,3}(:[a-zA-Z0-9\x0600-\x06FF\x0750-\x077F\xFB50-\xFDFF\xFE70-\xFEFF]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~\x0600-\x06FF\x0750-\x077F\xFB50-\xFDFF\xFE70-\xFEFF])*$

查看更多
姐就是有狂的资本
4楼-- · 2020-02-15 08:19

The best option is to use an Unicode chracter class for that. It would be \p{Arabic} for your case. But don't forget that you should also add the Unicode PCRE modifier /u at the end.

查看更多
登录 后发表回答