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

 

posted @   波罗斯の程序日记  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2018-06-18 PHP简单爬虫 爬取免费代理ip 一万条
点击右上角即可分享
微信分享提示