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

How to replace backslashes in PHP?

Guanhui
Release: 2023-03-02 18:22:01
Original
5169 people have browsed it

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
Copy after login

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

<?php
// 赋值: <body text=&#39;black&#39;>
$bodytag = str_replace("%body%", "black", "<body text=&#39;%body%&#39;>");

// 赋值: 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;
?>
Copy after login

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!

Related labels:
php
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