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