search
Homephp教程php手册php 自定字符串中的部分字符进行替换方法

php 自定字符串中的部分字符进行替换方法

Jun 13, 2016 am 11:18 AM
phpcharacterstringTutorialmethodreplaceconductpart

 

php教程 自定字符串中的部分字符进行替换方法

substr_replace()函数对自定字符串中的部分字符进行替换
   语法:substr_replace(str,repl,start,[int length])
   语法说明:
   str——必选参数,指定要操作的原始字符串
   repl——指定替换后的新字符串
   start——指定替换字符串的开始位置
   length——可选参数,指定返回字符串的长度。
   使用substr_replace()函数替换字符串的应用实例:

实例代码:
$b=”手册”;
$c=”zero的php博客”;
echo substr_replace($c,$b,9,4);
?>
输出结果:
zero的php手册

 

参数 描述
string 必需。规定要检查的字符串。
replacement 必需。规定要插入的字符串。
start

必需。规定在字符串的何处开始替换。

  • 正数 - 在第 start 个偏移量开始替换
  • 负数 - 在从字符串结尾的第 start 个偏移量开始替换
  • 0 - 在字符串中的第一个字符处开始替换
charlist

可选。规定要替换多少个字符。

  • 正数 - 被替换的字符串长度
  • 负数 - 从字符串末端开始的被替换字符数
  • 0 - 插入而非替换

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment