6

I want to remove all non Arabic, non English and non Numbers charecters from a string, except for dashes (-).

I managed to do it for non English alphanumeric characters like this:

$slug = ereg_replace('[^A-Za-z0-9-]', '', $string);

But for non arabic alphanumeric characters i tried to do it like this:

$slug = ereg_replace('\p{InArabic}', '', $string);

but it didnt strip the non alphanumeric characters! I also tried this answer but it didnt work either, it always returns '0' !!

$slug = preg_replace('/[^\x{0600}-\x{06FF}A-Za-z0-9-]/u','', $string);

Hopefully someone can help me.

Community
  • 1
  • 1
Waleed Asender
  • 1,477
  • 15
  • 27

1 Answers1

10

Try the below:

$slug = preg_replace('/[^\p{Arabic}\da-z-]/ui', '', $string);
xdazz
  • 158,678
  • 38
  • 247
  • 274