function to replace string in php

下次还敢
Release: 2024-04-29 12:36:15
Original
710 people have browsed it

The functions used to replace strings in PHP are as follows: 1. str_replace(), used to replace matching items in the string; 2. str_ireplace(), similar to str_replace(), but different Upper and lower case; 3. preg_replace(), uses regular expressions for string replacement.

function to replace string in php

Function to replace string in PHP

Question: Used to replace string in PHP What are the string functions?

Answer: The following functions are provided in PHP for replacing strings:

1. str_replace()

str_replace() Function is used to replace one or more matches in a string.

Syntax:

<code class="php">str_replace(string needle, string replace, string subject)</code>
Copy after login

Parameters:

  • needle - The string to find and replace
  • replace - the string to replace needle
  • subject - the string to replace

## 2. str_ireplace()

str_ireplace() function is similar to str_replace(), except that it is case-sensitive.

Syntax:

<code class="php">str_ireplace(string needle, string replace, string subject)</code>
Copy after login
Parameters:

  • needle - The string to find and replace
  • replace - the string to replace needle
  • subject - the string to replace
## 3. preg_replace()

preg_replace()

function uses regular expressions to replace strings. Syntax:

<code class="php">preg_replace(string pattern, string replacement, string subject)</code>
Copy after login

Parameters:

    pattern
  • - Regular expression used to match strings
  • replacement
  • - The string to replace the match with
  • subject
  • - The string to replace

The above is the detailed content of function to replace string in php. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template