php獲取某個(gè)字符字母最后位置

字號(hào):


    <?php
    //php獲取最后一個(gè)特定字符位置,函數(shù)如下,
    /*
    * forasp 要查找的字符串
    * cn是要查找的特定字符
    */
    function get_last_code_pos($forasp,$cn){
    $forasparr= explode($cn,$forasp);
    $lastforaspcn = $forasparr[count($forasparr)-1];//獲取最后的一個(gè)分組
    return strlen($forasp)-strlen($lastforaspcn)-1;
    }
    $forasp = "這里是要查詢的字符串,www,www,forasp.cn,www網(wǎng)站制作學(xué)習(xí)網(wǎng)原創(chuàng),php獲取特定字符位置forasp.cn";//3w.foa($)sp.cn
    $cn ="www";
    echo get_last_code_pos($forasp,$cn);
    //結(jié)果51,在utf8下中文占3個(gè)字符位置
    $forasp = "abcdefgabcdefasp.cn";
    $cn ="c";//獲取最后一個(gè)字符c的位置
    echo get_last_code_pos($forasp,$cn);
    //結(jié)果17