📅  最后修改于: 2023-12-03 15:18:21.308000             🧑  作者: Mango
This script allows you to check if a given text in PHP contains Cyrillic characters. It's useful when dealing with multilingual websites or applications that need to support different languages.
<?php
require_once 'cyrillic-check.php';
$text = 'Привет, мир!'; // This is a Cyrillic text
$containsCyrillic = is_cyrillic($text);
if ($containsCyrillic) {
echo "The text contains Cyrillic characters";
} else {
echo "The text doesn't contain Cyrillic characters";
}
?>
The result of the above code will be:
The text contains Cyrillic characters
The is_cyrillic
function uses the regular expression /[\p{Cyrillic}]/u
to match any Cyrillic character present in the text. The u
modifier is used to indicate that the regular expression should be treated as Unicode.
By using this script, you will be able to easily detect if a given text in PHP contains Cyrillic characters. This can help you ensure that your web applications are properly supporting different languages and character sets.