网站制作学习网PHP→正文:php获取某个字符字母最后位置
字体:

php获取某个字符字母最后位置

PHP 2013/9/12 16:55:13  点击:不统计

http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E

 <?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
//网站制作学习网原创

forasp.cn

·上一篇:php PHP_SAPI >>    ·下一篇:php sleep 小于1秒 >>
推荐文章
最新文章