preg_replace 和 preg_match 阿拉伯字符 [英] preg_replace and preg_match arabic characters

查看:35
本文介绍了preg_replace 和 preg_match 阿拉伯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何将阿拉伯字母添加到 url 正则表达式

我已经搜索了几个小时没有答案.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆