G
G
ganbatte2019-12-25 12:42:51
PHP
ganbatte, 2019-12-25 12:42:51

Checking text for a non-text character in utf8. What are the ways to check?

On the Internet, I found this thing,

$pattern = "/([\p{L}]+)/u";
$string  = "你好,世界!Привет мир! !مرحبا بالعالم";
if (preg_match_all($pattern, $string, $match)) {
    var_dump($match);
}

array(2) {
  [0]=>
  array(6) {
    [0]=>
    string(6) "你好"
    [1]=>
    string(6) "世界"
    [2]=>
    string(12) "Привет"
    [3]=>
    string(6) "мир"
    [4]=>
    string(10) "مرحبا"
    [5]=>
    string(14) "بالعالم"
  }
  [1]=>
  array(6) {
    [0]=>
    string(6) "你好"
    [1]=>
    string(6) "世界"
    [2]=>
    string(12) "Привет"
    [3]=>
    string(6) "мир"
    [4]=>
    string(10) "مرحبا"
    [5]=>
    string(14) "بالعالم"
  }
}

It works, only it works the other way around, it returns true if it has at least one letter. And it is necessary that it works the other way around, returning true if it has at least one character.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2019-12-25
@ganbatte

preg_match_all does not cut anything from your text, by the way it will return true or false, you yourself look at the variable where this function writes the found matches

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question