Get the App
SLTechnology News&Howtos  ›  Development  › 

Why does php display only letters and numbers?

Shulou Source: shulou.com Published: 2022-05-31 18:55:34 10月03日 Update

In this article, the editor introduces in detail "php how to display only letters and numbers". The content is detailed, the steps are clear, and the details are handled properly. I hope this "php how to show only letters and numbers" article can help you solve your doubts.

Php can filter strings, displaying only 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])" to convert the array into a string.

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

Php can filter strings, displaying only letters and numbers.

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

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

The preg_match_all () function takes a third argument of an array type, which is used to store all matching results.

The array is a two-dimensional array, and the resulting value can be concatenated into a string using the join () function.

Join ('', $arr [0])

After reading this, the article "how php only displays letters and numbers" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Letters numbers characters strings arrays functions articles content regularities results expressions appropriateness parameters ideas tutorials new knowledge methods more steps environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn OPPO Reno Shulou Information Shulou Tech Info