Validating URLs with non traditional characters

53 Views Asked by At

I have a URL with special characters, example:

$url = 'https://example.com/c/ファンタシ.jpg';

I can't validate it with:

var_dump( (filter_var($url, FILTER_VALIDATE_URL)) );

Because it isn't a valid URL according to the RFC:

"Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL"

And I can't do:

urlencode($url);

Because that will encode the entire string with encoded slashes, colon etc.

So how do I encode the $url properly so it passed the validation?

0

There are 0 best solutions below