PHP 基础代码之 31 字符串函数 str_replace substr_replace strtoupper
实战需求
PHP有许多用于处理和操作字符串的内置函数。在这里可以看到一些更常用的字符串函数的例子。
解决方案
$a = 'String';
// Search and replace characters in a string
$b = str_replace('i', 'o', $a); // Strong
// Insert text at specified position
$b = substr_replace($a, 'My ', 0, 0); // My String
// Get part of string specified by start and length
$b = substr($a, 0, 3); // Str
// Convert to uppercase
$b = strtoupper($a); // STRING
// Find position of the first occurrence of a substring
$i = strpos($a, 'i'); // 3 (starts at 0)
// Get string length
$i = strlen($a); // 6
加入我们共同交流
群名称:PHP源码大全
QQ群号:907415141