首页 > 技术文章 > php--某个字符在字符串中的位置比较

lixiuran 2015-12-27 10:39 原文

<?php


$haystack = 'helloe';
$needle   = 'e';

$pos      = stripos($haystack, $needle);

echo "\n";

echo $pos;die;  // 加r的是5 ,不加r的是 1,索引值从0开始,所以判断时 要 false !== $pos 来判断

/*

stripos

(PHP 5)
stripos — Find the position of the first occurrence of a case-insensitive substring in a string

strpos

(PHP 4, PHP 5)
strpos — Find the position of the first occurrence of a substring in a string

查看一个字符在字符串中首次出现的位置,i 表示忽略大小写

strripos

(PHP 5)
strripos — Find the position of the last occurrence of a case-insensitive substring in a string


strrpos

(PHP 4, PHP 5)
strrpos — Find the position of the last occurrence of a substring in a string

查看一个字符在字符串中最后一次出现的位置,i 表示忽略大小写

*/

  

推荐阅读