php中几个字符串替换函数详解

如题所述

第1个回答  2019-10-15
  一、str_replace(find,replace,string,count)
  作用:str_replace()
函数使用一个字符串替换字符串中的另一些字符。
  参数
描述
  find
必需。规定要查找的值。
  replace
必需。规定替换
find
中的值的值。
  string
必需。规定被搜索的字符串。
  count
可选。一个变量,对替换数进行计数。
  二、substr_replace(string,replacement,start,length)
  作用:substr_replace()
函数把字符串的一部分替换为另一个字符串。
  参数
描述
  string
必需。规定要检查的字符串。
  replacement
必需。规定要插入的字符串。
  start
必需。规定在字符串的何处开始替换。
  三、preg_replace
(
pattern
,
replacement
,
subject,limit
=
-1
,$count
)
  作用:执行一个正则表达式的搜索和替换
  参数
描述
  pattern
必需。需要搜索的模式。
  replacement
必需。用于替换的字符串或数组。
  subject
必需。需要替换的字符串或数组。
  limit
替换的次数。-1为无限
  count
完成替换的次数,变量
  Example
#1
使用后向引用紧跟数值原文