Can php only display letters and numbers?

青灯夜游
Release: 2023-03-15 20:40:02
Original
2215 people have browsed it

php can filter strings and only display letters and numbers. Implementation method: 1. Use "preg_match_all("/[a-zA-Z0-9]/u", "$str", $arr)" to find letters and numbers and store them in the array; 2. Use "join ('',$arr[0])" converts the array into a string.

Can php only display letters and numbers?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php can filter strings, only Display letters and numbers.

In PHP, you can use the preg_match_all() function with regular expressions to filter strings and only retain English letters and numbers.

The regular expression used is: /[a-zA-Z0-9]/u

##preg_match_all() function accepts an array The third parameter of the type is used to store all matching results.

<?php
header("Content-type:text/html;charset=utf-8");
$str = "php.cn?php中文网。zblog,?#$%^&())*(&^";
preg_match_all("/[a-zA-Z0-9]/u","$str",$arr);
var_dump($arr);
?>
Copy after login

Can php only display letters and numbers?

The array is a two-dimensional array, you can use the join() function to splice the result values ​​into a string

join(&#39;&#39;,$arr[0])
Copy after login

Can php only display letters and numbers?

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of Can php only display letters and numbers?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!