Home > Backend Development > PHP Problem > What function is used to replace strings and characters in php

What function is used to replace strings and characters in php

王林
Release: 2023-03-03 16:00:01
Original
3056 people have browsed it

Str_replace() function is used to replace strings and characters in php. The str_replace() function replaces some characters in a string (case-sensitive). The function syntax is: [str_replace(find,replace,string,count)].

What function is used to replace strings and characters in php

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

(Recommended tutorial: php graphic tutorial)

Function syntax:

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

(Recommended video tutorial: php video Tutorial)

Parameter description:

  • 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 example:

<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
Copy after login

The above is the detailed content of What function is used to replace strings and characters 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