Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove symbols from a string by php

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "php how to remove the symbols in the string", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php how to remove the symbols in the string" article.

Methods: 1, remove the specified symbols with "str_replace (" specified symbols ",", $str) "; 2, use" preg_match_all ("/ [\ x {4e00} -\ x {9fa5} a-zA-Z0-9] / u", "$str", $result); filter out all symbols.

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

Php removes symbols from a string

Method 1: use the str_replace () function to remove the specified symbol

The str_replace () function searches for a specified symbol in a string and replaces it with an empty character.

For example: get rid of? Symbol

Method 2: use the preg_match_all () function

The preg_match_all () function can filter strings with regular expressions, leaving only Chinese, English and numbers, and removing all other symbols.

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

You can use the join () function to concatenate the resulting array into a string

Echo join ('', $result [0])

The above is about the content of this article on "how to remove symbols from a string in php". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report