如何检查字符串是否包含特殊字符


How to check whether a string contains special characters

我有一个csv文件。当它以字符集"UTF-8"打开时,它包含一些值,例如

Bedre Psykiatri - Landsforeningen for p?ɬ•r?ɬ?rende
Central de Atendimento T?جø¬?cnico
Centro de Extens?جø¬?o Universit?جø¬?ria
Centro Universit?جø¬?rio Feevale

现在,我有php脚本,它可以读取上面的csv文件。

让我知道,如何检查从csv文件中获取的字符串是否是上述模式的类型?

你可以这样做

<?php
$illegal = "#$%^&*()+=-[]';,./{}|:<>?~";
echo (false === strpbrk($YourCsvVarible, $illegal)) ? 'Allowed' : "Disallowed";
?>

注意: strpbrk(string,charlist)当字符串不包含您在 2ed 参数中传递的字符时,它将返回 false,如果您需要更多 http://php.net/manual/en/function.strpbrk.php,请参阅我已经传递了$illegal = "#$%^&*()+=-[]';,./{}|:<>?~";中的所有字符