我尝试了很多东西并且搜索了很多,而且我没有成功... 我该怎么办?
@edit:
if (!preg_match("/^[\p{L}-]*$/u", $line)){
我已尝试使用此thread但未使用此功能。
我想做什么?只接受我要过滤此列表的单词: List
@ edit2:已经尝试使用iconv,mb_convert_encoding等将convertind转换为UTF8 ...
答案 0 :(得分:2)
它认为这就是你要找的东西:
if (preg_match("/[a-zA-Z0-9áéíóúÁÉÍÓÚ\s]*/", $line)){
// line is ok
}
您可以在此处测试:https://regex101.com/r/4Ozxw2/1
答案 1 :(得分:0)
像
这样的东西<?php
$strings = ['hash#', 'percent%', '!exc', 'ó','-',',','num1'];
foreach($strings as $v) {
if (preg_match("/^[\p{L}A-Za-z0-9,!]*$/u", $v)) {
print $v . '<br/>';
}
}
答案 2 :(得分:0)
使用此...
<?php
$strings = ['test(yes)h#', 'test2%', '!test3', 'ó','-',',...','test'];
foreach($strings as $v) {
if (preg_match("/^[\p{L}A-Za-z0-9! | #\((.*?)\)#]*$/u", $v)) {
print $v . '<br/>';
}
}
?>
我认为这将解决您的问题。