当前位置:Gxlcms > PHP教程 > php字符反转

php字符反转

时间:2021-07-01 10:21:17 帮助过:3人阅读

1.使用php自带函数实现
测试代码

$str='Hello World!';
$res=strrev($str);
echo$res.'
'
; $str='Hello World!你好 世界!'; $res=reverse($str); echo$res; //自定义函数functionreverse($str) {$len = mb_strlen($str, 'utf-8'); for ($i = 0; $i < $len; $i++) { $arr[] = mb_substr($str, $i, 1, "utf-8"); } return implode("", array_reverse($arr)); } ?>

运行结果
!dlroW olleH!
界世 好你!dlroW olleH

2.c语言实现

#include #includechar *str="Hello World!你好 世界!";

int main() {
  int i = strlen(str) - 1;
  while (i>=0) {

        if(str[i] < 0)
        {
                printf("%c%c%c\n", str[i-2], str[i-1],str[i]);
                i = i-2;
        }else{
                printf("%c\n", str[i]);
        }
        i--;
  }
  return0;
}

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了php 字符反转,包括了include方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行