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

No ideas.......

Member Avatar for diafol
$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?

Hi Diafol
Thanks for your reply

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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.