str_getcsv()
// 使用 str_getcsv() 将一个 CSV 字符串解析为一个数组 $csv = '"John","Doe","john@example.com","555-123-4567"'; $arr = str_getcsv($csv); print_r($arr); // 输出 Array ( [0] => John [1] => Doe [2] => john@example.com [3] => 555-123-4567 )
str_ireplace()
// 使用 str_ireplace() 替换字符串中的字符 $str = 'Hello World'; $str = str_ireplace('WORLD', 'PHP', $str); echo $str; // 输出 Hello PHP
str_pad()
// 使用 str_pad() 将字符串填充到指定的长度 $str = 'Hello'; $str = str_pad($str, 10, '-', STR_PAD_BOTH); echo $str; // 输出 --Hello---
str_repeat()
// 使用 str_repeat() 重复指定字符串 $str = 'Hello'; $str = str_repeat($str, 3); echo $str; // 输出 HelloHelloHello
str_shuffle()
// 使用 str_shuffle() 打乱字符串 $str = 'Hello World'; $str = str_shuffle($str); echo $str; // 输出 rWoelHl odl
str_split()
// 使用 str_split() 将字符串分割为数组 $str = 'Hello World'; $arr = str_split($str); print_r($arr); // 输出 Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => W [7] => o [8] => r [9] => l [10] => d )
str_word_count()
// 使用 str_word_count() 统计字符串中的单词数 $str = 'Hello World'; $count = str_word_count($str); echo $count; // 输出 2
strip_tags()
// 使用 strip_tags() 删除字符串中的 HTML 标签 $str = 'Hello World
'; $str = strip_tags($str); echo $str; // 输出 Hello World
substr_count()
// 使用 substr_count() 统计字符串中某个子串出现的次数 $str = 'Hello World'; $count = substr_count($str, 'l'); echo $count; // 输出 3
trim()
// 使用 trim() 删除字符串两端的空白字符 $str = ' Hello World '; $str = trim($str); echo $str; // 输出 Hello World