preg_replace和preg_match阿拉伯字符 [英] preg_replace and preg_match arabic characters
问题描述
可能重复:
如何在url正则表达式中添加阿拉伯字母
Possible Duplicate:
how to add Arabic letters to url regex
我已经搜索了几个小时而没有答案.
I have been searching a couple of hours without an answer.
您如何在英语和阿拉伯字符上使用preg_replace?
How do you use preg_replace on arabic characters as well as english?
这是我的代码是英语
$string = preg_replace ( "/&([a-zA-Z])(uml|acute|grave|circ|tilde|ring),/", "", $string );
$string = preg_replace ( "/[^a-zA-Z0-9_.-]/", "", $string );
我使用此代码建议的一些答案:
some of the answers suggested i use this code:
$string = preg_replace ( "/&([أ-يa-zA-Z])(uml|acute|grave|circ|tilde|ring),/u", "", $string );
$string = preg_replace ( "/[^أ-يa-zA-Z0-9_.-]/u", "", $string );
我已经对其进行了测试,并且可以正常工作.但这实际上对php有用吗?它包括所有阿拉伯字符吗?有没有更好的方法来包含所有阿拉伯字符?
I have tested it and it works. but is this actually functional for php? does it include all arabic characters? is there a better way to include all arabic characters?
我要处理的代码是:
将字符串中的所有字符替换为有效的SEO友好字符.
Replace all characters in the string to valid SEO friendly characters.
我使用基于 http://www.unicodemap.org 的代码解决了该问题.谢谢布莱恩.
I solved the problem using this code based on http://www.unicodemap.org. Thank you Bryan.
$string = preg_replace ( "/&([\x{0600}-\x{06FF}a-zA-Z])(uml|acute|grave|circ|tilde|ring),/u", "", $string );
$string = preg_replace ( "/[^\x{0600}-\x{06FF}a-zA-Z0-9_.-]/u", "", $string );
推荐答案
unicode字符映射图很棒可视化包括字符串的第一部分用[أ-يa-zA-Z]
The unicode character map is a great place to visualize the groups of characters including Arabic that the first part of the string is grouping for you with [أ-يa-zA-Z]
如果您仍然不确定,请阅读正则表达式的更多内容.
If you are still unsure, read up a little more on regular expressions.
这篇关于preg_replace和preg_match阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!