Home > Backend Development > PHP Problem > How to delete invisible characters in php

How to delete invisible characters in php

藏色散人
Release: 2023-03-04 11:50:01
Original
3700 people have browsed it

php method to delete invisible characters: first open the background php code file; then delete the invisible Unicode characters directly through the "preg_replace($pattern, "", '‎');" method .

How to delete invisible characters in php

Recommended: "PHP Video Tutorial"

php delete invisible Unicode characters

In forums/communities, the title of a general post/article must not be empty, but today I discovered a magical thing. I restricted the title from being empty in the background php code.

if(preg_match('/^\s*$/', $val)) return false;
Copy after login

But magically, I found that there are several articles in the database whose titles are empty (it looks to the eye)

How to delete invisible characters in php

and I clicked the mouse to select them. It was indeed empty. However, when printing through var_dump, I found that this "null character" occupied three lengths

How to delete invisible characters in php

The last person who found this string was '\u200e', in the editor of Seventeen Degrees Shown here is such a symbol.

How to delete invisible characters in php

# Then the copied string is indeed an empty string, so I can only find a way to delete it.

$pattern = "/[\x{007f}-\x{009f}]|\x{00ad}|[\x{0483}-\x{0489}]|[\x{0559}-\x{055a}]|\x{058a}|[\x{0591}-\x{05bd}]|\x{05bf}|[\x{05c1}-\x{05c2}]|[\x{05c4}-\x{05c7}]|[\x{0606}-\x{060a}]|[\x{063b}-\x{063f}]|\x{0674}|[\x{06e5}-\x{06e6}]|\x{070f}|[\x{076e}-\x{077f}]|\x{0a51}|\x{0a75}|\x{0b44}|[\x{0b62}-\x{0b63}]|[\x{0c62}-\x{0c63}]|[\x{0ce2}-\x{0ce3}]|[\x{0d62}-\x{0d63}]|\x{135f}|[\x{200b}-\x{200f}]|[\x{2028}-\x{202e}]|\x{2044}|\x{2071}|[\x{f701}-\x{f70e}]|[\x{f710}-\x{f71a}]|\x{fb1e}|[\x{fc5e}-\x{fc62}]|\x{feff}|\x{fffc}/u";
$str = '‎'; // 三个长度
$str = preg_replace($pattern, "", '‎');
var_dump($str); // 0长度
Copy after login

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

Related labels:
php
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