/*
int mb_strlen ( string $str [, string $encoding ] )
代码如下 | 复制代码 |
echo substr_replace("Hello world","earth",6); Hello earth ?> |
值得一提的,当开始和长度都是负和,长度小于或等于开始,长度将有被设置为0的效果。
代码如下 | 复制代码 |
substr_replace('eggs','x',-1,-1); //eggxs substr_replace('eggs','x',-1,-2); //eggxs substr_replace('eggs','x',-1,-2); //eggxs ?> |
Same as:
substr_replace('eggs','x',-1,0); //eggxs
?>
代码如下 | 复制代码 |
substr_replace('huevos','x',-2,-2); //huevxos substr_replace('huevos','x',-2,-3); //huevxos substr_replace('huevos','x',-2,-3); //huevxos ?> |
Same as:
代码如下 | 复制代码 |
substr_replace('huevos','x',-2,0); //huevxos ?> |
另一个注意,如果长度为负,开始偏移为长度相同的位置,长度(再次)将具有影响被定为0。 (当然,在手册中提到,当长度为负它实际上代表了之前的立场)
代码如下 | 复制代码 |
substr_replace('abcd', 'x', 0, -4); //xabcd Same as:
substr_replace('abcd', 'x', 1, -3); //axbcd Same as: |
看一下参数说明
string 必需。规定要检查的字符串。
replacement 必需。规定要插入的字符串。
start 必需。规定在字符串的何处开始替换。
正数 - 在第 start 个偏移量开始替换
负数 - 在从字符串结尾的第 start 个偏移量开始替换
0 - 在字符串中的第一个字符处开始替换
charlist 可选。规定要替换多少个字符。
正数 - 被替换的字符串长度
负数 - 从字符串末端开始的被替换字符数
0 - 插入而非替换

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
