You need to check the URL for the presence of invalid characters in the URL. Checking the trail. way:

if(!preg_match('/[^0-9a-zA-Z.\-\/:?&=#%_]/', $url)) { ... } 

What to do when using Cyrillic characters and other alphabets?

  • one
    If the UTF-8 code itself you can easily write to the Cyrillic alphabet in the form of AZ directly to the regular calendar, you may need to add the letter “E” separately. And after closing the regular season / you need to put the letter 'u' - the flag of using UTF in the expression - Mike
  • one
    @Mike, what about the IDN and the "ñ" symbol? After all, it is valid in Spanish. - Dmitriy Simushev
  • one
    @DmitriySimushev I do not know. If I knew, I would have written the answer. And so only indicated a possible direction for the decision - Mike

2 answers 2

\W Does not fit?

Matches any non-numeric character. Equivalent to [^ A-Za-z0-9_].

    I can only prompt to install the Russian locale:

     setlocale(LC_ALL, "ru_RU.UTF-8"); 

    the regular itself should be with the key \ u

     !preg_match('/[^A-Za-z0-9а-яА-Я.\-\/:?&=#%_]/u', $url)