PHP uses one string to modify characters in another string
阿神
阿神 2017-05-16 13:01:01
0
2
305

阿神
阿神

闭关修行中......

reply all(2)
阿神

In PHP, a string is an array of bytes. Use curly braces and numeric subscripts to access or modify the corresponding single character in the string. Note that it is a single character!

$str{1} in your code can only hold one character, and your assignment is 5 characters. At this time, php will only take the first character by default, so its result will naturally be lnmp.

In addition, the official PHP documentation also says that using curly braces to access or modify strings is very unsafe for multi-byte character sets. Try not to use {} when you use other encoding sets such as UTF-8 or GBK.

曾经蜡笔没有小新

String string

A string string is composed of a series of characters, where each character is equivalent to one byte. This means that PHP can only support a character set of 256 and therefore does not support Unicode. See the detailed explanation of string types for details.

Quoted from the PHP manual. Indicated in bold. Each character is a byte. Therefore, only one byte position can be replaced.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template