Home > Backend Development > PHP Tutorial > str_replace function in PHP

str_replace function in PHP

WBOY
Release: 2016-07-29 09:12:38
Original
1737 people have browsed it
In the process of PHP word processing, we may have these operations, such as changing the first two words in the article to a larger font, or replacing the color of some fonts from the original bold to red fonts, or in the forum Some fonts that violate civility are blocked, etc. These are all used by our str_replace function. Let’s introduce the use of str_replace function

Syntax:str_replace(find,replace,string,count)

find: Specifies the value to be found.

replace: Specifies the value to be replaced. This value is also used to replace the value in find.

string: Specifies the string to be searched.

count: Count the number of substitutions.

Let’s list a few examples of combining functions

1. Change the color of the found value

$str = "hello, world!";

$find = 'hello';

echo (str_replace($find, "".$find."", $str));

2. Change the size of the found value

$str = "hello, world!";

$find = 'hello';

echo (str_replace($find, "".$find."", $str));

It is worth mentioning that the use of str_replace is very simple, but in It is very useful when doing projects. In fact, it can also play a role in many places. As long as you observe carefully, you will definitely find a lot of fun. In addition, str_replace is case-sensitive. We should replace it with str_ireplace when we are doing projects. Remember, remember.

The above has introduced the str_replace function in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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