Home >Backend Development >PHP Problem >How to filter out invisible special strings in php

How to filter out invisible special strings in php

王林
王林Original
2021-09-18 15:31:222613browse

php method to filter out invisible special strings: [$content = '123456 1'; $len = strlen($content); $str = ""; for($i=0;$ i<$len;$i ){if((ord($co...].

How to filter out invisible special strings in php

##The operating environment of this article: windows10 system, php7, thinkpad t480 Computer.

It must be a very simple thing for friends who have learned PHP to filter strings. We can complete the filtering through regular expressions or PHP's own functions. But for those who How can we filter out invisible special characters accurately?

Let’s take a look at the specific implementation code:

$content = &#39;123456   1&#39;;
 
$len = strlen($content);
 
$str = "";
 
for($i=0;$i<$len;$i++){
 
              if((ord($content[$i]) >= 0x30 && ord($content[$i]) <= 0x39) || $content[$i] == "." || $content[$i] == " " ||                             $content[$i] == "\t" || $content[$i] == "\n"){
 
                        $str = $str.$content[$i];
 
              }
 
          }

Recommended learning:

php training

The above is the detailed content of How to filter out invisible special strings in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn