Home>Article>Backend Development> How to replace backslashes in PHP?

How to replace backslashes in PHP?

Robert De Niro
Robert De Niro Original
2020-07-20 17:07:12 5006browse

How to replace backslashes in PHP?

#How to replace backslashes in PHP?

In php, you can use the "str_replace()" function to replace the backslash. This function is used to replace some characters in the string. How to use: Pass the backslash into the first Parameters, the second parameter is left blank, the third parameter is the string to be replaced, and finally the return value is received.

Syntax

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

Parameters

if search and replace are both arrays, and their values will be processed sequentially.

search

The target value to find, which is needle. An array can specify multiple targets.

replace

The replacement value of search. An array can be used to specify multiple replacements.

subject

Array or string to perform replacement. That is haystack.

If subject is an array, the replacement operation will traverse the entire subject, and the return value will also be an array.

count

If specified, its value will be set to the number of times replacement occurred.

Example

 $bodytag = str_replace("%body%", "black", ""); // 赋值: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); // 赋值: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); // 赋值: 2 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; ?>

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

Statement:
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