您的位置:首页 > 编程语言 > PHP开发

PHP学习笔记:字符串

2019-03-31 16:48 141 查看

PHP之字符串

字符串

学习的内容太多,用文章记录知识点可以加深印象,也方便查询!

字符串查找

  1. strpos — 查找字符串首次出现的位置

strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int

返回 needle 存在于 haystack 字符串起始的位置(独立于 offset)。同时注意字符串位置是从0开始,而不是从1开始的。
如果没找到 needle,将返回 FALSE。

Warning
此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值。应使用 === 运算符来测试此函数的返回值。

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作,
// 因为 'a' 是第 0 位置上的(第一个)字符。
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
  1. stristr — strstr() 函数的忽略大小写版本

stristr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string

<?php
$array = array();
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: