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

How to filter out invisible special strings in php

王林
Release: 2023-03-12 17:56:01
Original
2577 people have browsed it

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];
 
              }
 
          }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template