PHP中常用字符串函数
// strlen 取字符串长度
$string = "Hello, world!";
$length = strlen($string);
echo $length; // 输出:13
// strpos 找字符串,返回位置
$str = "hello world";
$position = strpos($str,"world");
echo $position; // 输出:7
// substr 截取字符串
$str = "hello world";
$substring = substr($str,7,5); // 从第7位开始 截取5个字符
echo $substring; // 输出:world
// str_replace 替换字符串
$str = "hello world";
$newStr = str_replace("world","php",$str);
echo $newStr; // 输出:hello php
// strtolower 字符串转小写
$str = "Hello WORLD";
$lowStr = strtolower($str);
echo $str; // 输出:hello world
// strtoupper 字符串转大写
$str = "hello world";
$upStr = strtoupper($str);
echo $upStr; // 输出:HELLO WORLD
// trim 去首尾空或指定字符
$str = " hello world ";
$newStr = trim($str);
echo $newStr; // 输出:hello world
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2018-06-18 PHP简单爬虫 爬取免费代理ip 一万条