Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete an element in a string in php

Shulou Source: shulou.com Published: 2022-06-01 07:04:57 09月16日 Update

In this article, the editor introduces in detail "how to delete an element in a string in php". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to delete an element in a string in php" can help you solve your doubts.

Php method to delete an element in a string: 1, use str_replace (), syntax "str_replace (" value to be deleted ",", $str) "; 2, use str_ireplace (), syntax" str_ireplace ("value to be deleted", ", $str)".

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

Delete an element from a string in php

Method 1: use the str_replace () function

The str_replace () function replaces some characters in the string with other characters (case-sensitive); when the replacement value is an empty string "", you can delete the specified value.

Syntax:

The str_replace (find,replace,string,count) parameter is required to describe find. Specifies the value to look for. Replace is required. Specifies the value that replaces the value in find. String is required. Specifies the string to be searched. Count is optional. A variable that counts the number of substitution.

Example:

Method 2: use the str_ireplace () function

The str_ireplace () function replaces some characters in the string (case-insensitive); similarly, when the replacement value is an empty string "", you can delete the specified value.

The syntax of the str_ireplace () function is similar to that of the str_replace () function, as shown above.

Example:

After reading this, the article "how to delete an element in a string in php" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, please follow the industry information channel.

Tags: Characters strings elements functions syntax articles methods content size examples empty characters appropriateness similarity parameters variables ideas tutorials new knowledge more steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei macOS Shulou Technology Redmi