preg_replace and preg_match arabic characters

Viewed 10290

Possible Duplicate:
how to add Arabic letters to url regex

I have been searching a couple of hours without an answer.

How do you use preg_replace on arabic characters as well as english?

this is my code is 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 );

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?

What i am going to do with the code is:

Replace all characters in the string to valid SEO friendly characters.

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 );
2 Answers
Related