Home > Backend Development > PHP Problem > How to remove a certain character from a php string

How to remove a certain character from a php string

青灯夜游
Release: 2023-03-08 21:48:01
Original
3796 people have browsed it

In PHP, you can use the str_replace() function to remove a certain character in a string. str_replace() is used to replace some characters in a string in a case-sensitive manner. The syntax format "str_replace('To remove characters','',string)".

How to remove a certain character from a php string

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

php remove a certain character from the string

In PHP, you can use the str_replace() function to remove a certain character in a string.

Example: Remove the a character from the string

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$str="abcdefg";
echo "原字符串:",$str,"<br>";
$str=str_replace(&#39;a&#39;,&#39;&#39;,$str);
echo "去掉a字符的字符串:",$str;
?>
Copy after login

Output:

原字符串:abcdefg
去掉a字符的字符串:bcdefg
Copy after login

Related function description:

str_replace() Function replaces some characters in a string (case sensitive).

This function must follow the following rules:

  • If the searched string is an array, then it will return an array.

  • If the searched string is an array, then it will find and replace each element in the array.

  • If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings .

  • If you search an array and replace only one string, the replacement string will work for all found values.

Grammar

str_replace(find,replace,string,count)
Copy after login

How to remove a certain character from a php string

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove a certain character from a php string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template