当前位置:网站首页>Preg in PHP_ How to replace variable data
Preg in PHP_ How to replace variable data
2022-06-25 01:36:00 【Yisu cloud】
php in preg_replace How to replace variable data
This article mainly explains “php in preg_replace How to replace variable data ”, Interested friends might as well come and have a look . The method introduced in this paper is simple and fast , Practical . Now let Xiaobian take you to learn “php in preg_replace How to replace variable data ” Well !
stay php in ,“preg_replace” Function can perform a regular expression search and replace to replace variable data , The grammar is “preg_replace( Specify the mode of search , String or array of strings to replace , The target string or array of strings to search for replacement , The maximum number of times a string can be replaced , The number of times the replacement is executed )”; if subject Is an array, the returned result is an array , Otherwise, return the string .
This article describes the operating environment :Windows10 System 、PHP8.1 edition 、Dell G3 The computer
php in preg_replace Method of replacing variable data
preg_replace Function to search and replace a regular expression .
grammar
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
Search for subject Match pattern Part of , With replacement Replace .
Parameter description :
$pattern: Patterns to search , It can be a string or an array of strings .
$replacement: String or array of strings to replace .
$subject: The target string or array of strings to search for replacement .
$limit: Optional , For each pattern, for each subject The maximum number of times a string can be replaced . The default is -1( unlimited ).
$count: Optional , The number of times the replacement was performed .
Return value
If subject Is an array , preg_replace() Returns an array , In other cases, a string is returned .
If the match is found , After replacement subject Returned , In other cases Go back to what hasn't changed subject. If an error occurs , return NULL.
Examples are as follows :
<?php$string = 'The quick brown fox jumped over the lazy dog.';$patterns = array();$patterns[0] = '/quick/';$patterns[1] = '/brown/';$patterns[2] = '/fox/';$replacements = array();$replacements[2] = 'bear';$replacements[1] = 'black';$replacements[0] = 'slow';echo preg_replace($patterns, $replacements, $string);?>
The results are shown below :
The bear black slow jumped over the lazy dog.
Here we are , I'm sure you're right “php in preg_replace How to replace variable data ” Have a deeper understanding of , You might as well put it into practice ! This is the Yisu cloud website , For more relevant contents, you can enter the relevant channels for inquiry , Pay attention to our , Continue to learn !
边栏推荐
- 百度语音合成语音文件并在网站中展示
- Use redis' sorted set to make weekly hot Reviews
- 纹理增强
- SQL aggregate function handling null [easy to understand]
- 1. package your own scaffold 2 Create code module
- Deep learning LSTM model for stock analysis and prediction
- leetcode:2104. 子数组范围和
- Is it reliable to open an account on the flush with a mobile phone? Is there any hidden danger in this way
- What to learn in VB [easy to understand]
- 动手学数据分析 数据建模和模型评估
猜你喜欢
Reading notes at night -- deep into virtual function
js数组对象转对象
Ideas and examples of divide and conquer
The latest QQ wechat domain name anti red PHP program source code + forced jump to open
多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%
How to prepare for the last day of tomorrow's exam? Complete compilation of the introduction to the second building test site
JVM directive
PS5连接OPPO K9电视不支持2160P/4K
Assembly language (3) 16 bit assembly basic framework and addition and subtraction loop
Ps5 connected to oppo K9 TV does not support 2160p/4k
随机推荐
15.线程同步的几种方法
天书夜读笔记——8.4 diskperf反汇编
【LeetCode】11、盛最多水的容器
[live review] 2022 Tencent cloud future community city operator recruitment conference and SaaS 2.0 new product launch!
Status quo analysis: how "one cloud and multi-core" can promote the rapid deployment of information innovation projects
"One good programmer is worth five ordinary programmers!"
海河实验室创新联合体成立 GBASE成为首批创新联合体(信创)成员单位
屡获大奖的界面控件开发包DevExpress v22.1官宣发布
SQL aggregate function handling null [easy to understand]
带马尔科夫切换的正向随机微分方程数值格式模拟
php中preg_replace如何替换变量数据
Boutique enterprise class powerbi application pipeline deployment
JVM directive
弹性蛋白酶中英文说明书
第04天-文件IO
pbcms添加循环数字标签
AUTOCAD——两种延伸方式
Abnova丨CSV 磁珠中英文说明
Tianshu night reading notes -- memory paging mechanism
全排列II[存在相同元素去重 + 标准回溯]