Home > Backend Development > PHP Tutorial > Usage analysis of preg_replace regular replacement in php [replace multiple values ​​at one time]

Usage analysis of preg_replace regular replacement in php [replace multiple values ​​at one time]

高洛峰
Release: 2023-03-05 06:50:01
Original
2116 people have browsed it

The example in this article describes the usage of preg_replace regular replacement in php. Share it with everyone for your reference, the details are as follows:

1.php’s preg_replace and str_replace are both default /g, replace them all

2. If you need to use regular expressions, you need to use preg_replace

<?php
$a = "abc defa
bcd ef";
$b= preg_replace("/\t|a/","",$a);
echo($b);
/*
输出:
bc def
bcd ef
*/
?>
Copy after login

In addition, comparing replace in js, I feel that the syntax of php is not beautiful

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var a="a b";
console.log(a.replace(/\t/g,""));
</script>
</body>
</html>
Copy after login

The running effect diagram is as follows:

Usage analysis of preg_replace regular replacement in php [replace multiple values ​​at one time]

I hope this article will help The above will be helpful to everyone in PHP programming.

For more analysis on the usage of preg_replace regular replacement in PHP [replacing multiple values ​​at one time], please pay attention to the PHP Chinese website for related articles!

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