When working with REGEX in PHP queries, what steps should be taken to ensure compatibility with different character encodings, such as UTF-8?

When working with REGEX in PHP queries, it is important to ensure compatibility with different character encodings, such as UTF-8. One way to achieve this is by using the "u" modifier in the REGEX pattern, which tells PHP to treat the pattern and subject strings as UTF-8 encoded. This ensures that the REGEX functions work correctly with UTF-8 characters.

$pattern = '/pattern/u';
$string = 'UTF-8 encoded string';

if (preg_match($pattern, $string)) {
    echo 'Match found!';
} else {
    echo 'No match found.';
}