删除阿拉伯语中的垃圾字符
我需要从字符串中删除所有非阿拉伯字符,最终在人们的帮助下来自 stack-overflow 能够提出以下正则表达式来删除所有非阿拉伯字符。
preg_replace('/[^\x{0600}-\x{06FF}]/u','',$string);
问题是上面也删除了空格。现在我发现我还需要来自 AZ,az,0-9, !@#$%^&*()
的字符。那么我需要如何修改正则表达式呢?
谢谢你
I needed to remove all non Arabic characters from a string and eventually with the help of people from stack-overflow was able to come up with the following regex to get rid of all characters which are not Arabic.
preg_replace('/[^\x{0600}-\x{06FF}]/u','',$string);
The problem is the above removes white spaces too. And now I discovered I would need character from A-Z,a-z,0-9, !@#$%^&*()
also. So how do I need to modify the regex?
Thanking you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您想要保留的角色添加到角色类别中:
Add the ones you want to keep to your character class:
假设您有这个字符串:
这将仅保留带有空格的阿拉伯字符。
这将使阿拉伯语和英语字符与数字保持一致,
这将在稍后回答您的问题。
assume you have this string:
this will keep arabic chars with spaces only.
this will keep Arabic and English chars with Numbers Only
this will answer your question latterly.
从上面的示例更详细地看,考虑下面是您的字符串:
代码:
允许:
英文字母、阿拉伯字母、0到9和字符!@#$%^&*( ).
删除:
所有 html 标签以及除上述之外的特殊字符In a more detailed manner from Above example, Considering below is your string:
Code:
Allows:
English letters, Arabic letters, 0 to 9 and characters!@#$%^&*().
Removes:
All html tags, and special characters other than above