美文网首页
常用的处理字符串的方法

常用的处理字符串的方法

作者: swoft_ | 来源:发表于2019-07-25 13:41 被阅读0次

explode 字符串转数组

substr 返回字符串 string 由 start 和 length 参数指定的子字符串。

<?php
$rest = substr("abcdef", -1);    // 返回 "f"
$rest = substr("abcdef", -2);    // 返回 "ef"
$rest = substr("abcdef", -3, 1); // 返回 "d"
?>

strstr — 查找字符串的首次出现

<?php
$email  = 'name@example.com';
$domain = strstr($email, '@');  //默认false
echo $domain; // 打印 @example.com

$user = strstr($email, '@', true); // 从 PHP 5.3.0 起
echo $user; // 打印 name
//true 返回之前的位置 false 返回之后的位置
?>

相关文章

网友评论

      本文标题:常用的处理字符串的方法

      本文链接:https://www.haomeiwen.com/subject/faqhrctx.html