首页 > PHP > 文章正文

自定义php字符串函数

更新时间:2019-09-11

[广州PHP]自定义php字符串函数。
自定义php字符串函数strrev();strlen();
代码如下:
[PHP] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
//字符串反转

    function getRevStr($str){
    $result = '';
    $len = mb_strlen($str);
    for($i=$len-1; $i>=0; $i--){
        $result .= mb_substr($str,$i,1);
    }
    return $result;
}
$str1 = 'php是最好的yuyan';
$str2 = 'oppiuyk';
echo getRevStr($str1).'<br>';
echo getRevStr($str2).'<br>';

//字符串长度

    function getStrLen111($str){          
            if($str == '' ) return 0;          
            $count = 0;        
            while(1){                                           
                    if (isset($str[$count])){                           
                            $count++;                          
                            continue; 
                    }else{                          
                            break;                 
                    }          
            }          
    return $count;  
    }
     $a='abcdefgh';
     var_dump(getStrLen111($a));

效果图:
图片描述

更多技术资讯可关注:gzitcast

原文链接:https://segmentfault.com/a/1190000020362113

相关文章
相关标签