0

Hello everyone i have a pattern that checks the given url is correct or not and this is working perfectly fine, but when i give arabic chrarcters in pattern it return false because of invalid URL. I want english and arabic chracter to check in URL. where i can do change or what i can add in this pattern so this pattern can also validate arabic character with english

// check if URL is valid format
 $pattern = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w]([-\d\w]{0,253}[\d\w])?\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.,\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.,\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.,\/\d\w]|%[a-fA-f\d]{2,2})*)?$/'; 
 $isLink = preg_match($pattern, $url); // Returns true if a link
3
Contributors
4
Replies
13
Views
3 Years
Discussion Span
Last Post by diafol
1
$pattern = "/[^\p{Arabic}]/u";
$text = "كتابxz";

preg_match_all($pattern,$text,$matches);
print_r($matches);

Will show 'x' and 'z' as not Arabic

When you look for the positive...

$pattern = "/\p{Arabic}/u";
$text = "كتابxz";

preg_match_all($pattern,$text,$matches);
echo "<pre>";
print_r($matches);
echo "</pre>";

I get this:

Array
(
    [0] => Array
        (
            [0] => ك
            [1] => ت
            [2] => ا
            [3] => ب
        )
)

Is that a start for you?

0

Hi Diafol
Thanks for your reply

So can i add this /\p{Arabic}/u in my exiting pattern that validate URL?

0

I think that arabic is urlencoded, so you may be able to get the original arabic back via urldecode. As I've never done this myself, I'm only speculating.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.