How to replace part of a string in php

藏色散人
Release: 2023-03-04 21:44:01
Original
2827 people have browsed it

How to implement partial string replacement in php: First create a PHP sample file; then use the "str_replace("red","black","red green yellow pink purple");" method to replace the string That’s it.

How to replace part of a string in php

Recommended: "PHP Video Tutorial"

php now replaces part of the string

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

This function returns a string or array. This string or array is the result of replacing all searches in the subject with replace.

1. $search, the string or array to be replaced

2. $replace, the string or array to be replaced

3. $subject, The string or array being queried

4. $count, optional, if specified, will be set to the number of replacements

5. Return value: This function returns the replaced array Or string (newly generated)

<?php
//实例一:字符串替换字符串
$str1 = str_replace("red","black","red green yellow pink purple");
echo $str1."";//输出结果为black green yellow pink purple
?>
Copy after login

The above is the detailed content of How to replace part of a string 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template