php获取某个字符字母最后位置
2014-09-10来源:易贤网

<?php

//php获取最后一个特定字符位置,函数如下,

/*

* forasp 要查找的字符串

* cn是要查找的特定字符

*/

function get_last_code_pos($forasp,$cn){

$forasparr= explode($cn,$forasp);

$lastforaspcn = $forasparr[count($forasparr)-1];//获取最后的一个分组

return strlen($forasp)-strlen($lastforaspcn)-1;

}

$forasp = "这里是要查询的字符串,www,www,forasp.cn,www网站制作学习网原创,php获取特定字符位置forasp.cn";//3w.foa($)sp.cn

$cn ="www";

echo get_last_code_pos($forasp,$cn);

//结果51,在utf8下中文占3个字符位置

$forasp = "abcdefgabcdefasp.cn";

$cn ="c";//获取最后一个字符c的位置

echo get_last_code_pos($forasp,$cn);

//结果17

更多信息请查看IT技术专栏

2026公务员·事业单位培训课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息