Home > Article > Backend Development > Can php only display letters and numbers?
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.
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.
##preg_match_all() function accepts an array The third parameter of the type is used to store all matching results.The regular expression used is:
/[a-zA-Z0-9]/u
<?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); ?>The array is a two-dimensional array, you can use the join() function to splice the result values into a string
join('',$arr[0])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!