Home > Backend Development > PHP Problem > What is the character replacement function in php

What is the character replacement function in php

王林
Release: 2023-03-02 12:38:01
Original
2528 people have browsed it

The character replacement function in php is str_replace(). The str_replace() function is used to replace some characters in a string. This function is case-sensitive. Function syntax: [str_replace(find,replace,string,count)].

What is the character replacement function in php

#The character replacement function in php is str_replace().

(Recommended tutorial: php tutorial)

Function introduction:

str_replace() function replaces some characters in the string (case sensitive) .

Note: This function is case-sensitive.

Function syntax:

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

Parameter introduction:

  • find Required. Specifies the value to look for.

  • replace Required. Specifies the value to replace the value in find .

  • #string Required. Specifies the string to be searched for.

  • #count Optional. A variable counting the number of substitutions.

Code implementation:

<?php
  //实例一:字符串替换字符串
  $str1 = str_replace("red","black","red green yellow pink purple");
  echo $str1."";  //输出结果为black green yellow pink purple
?>
<?php
  //实例二:字符串替换数组键值
  $arr = array("blue","red","green","yellow");
  $str1 = str_replace("red","pink",$arr,$i);
  print_r($str1);
?>
Copy after login

The above is the detailed content of What is the character replacement function in php. 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template