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 php deletes a character in a string

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Xiaobian to share with you how php to delete a character in the string, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Methods to delete characters: 1. Use str_replace() function, syntax "str_replace(specify character,'', $str)";2. Use substr_replace() function, syntax "substr_replace($str,'', specify character position,1)".

Operating environment of this tutorial: Windows 7 system, PHP 7.1 version, DELL G3 computer

Php method to delete a character in a string

Method 1: Delete the specified character

In PHP, str_replace () and str_replace a specified string (character) in the original string with a new string; when the replacement value is set to the null character '', the specified character is deleted.

Note: str_replace is case sensitive, str_replace () is case insensitive.

Example 1: Using str_replace()

Output:

bcdefgACabcdefgC

Example 2: Using str_replace ()

Output:

bcdefgCbcdefgC

Method 2: Delete characters at specified positions

The substr_replace() function replaces part of a string with another string.

The syntax of the substr_replace() function is as follows:

mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )

substr_replace() replaces the substring qualified by the start and optional length parameters with replacement in a copy of string. If the replacement value is the null character '', characters of length can be deleted.

Examples:

Output:

The above is "php how to delete a character in the string" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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