zoukankan      html  css  js  c++  java
  • PHP学习笔记-字符串练习续

            1.字符串分割函数str_split($str,length),$str是要切割的字符串,length是分割长度,不写则默认是1,如果是负数则返回false

    1 $str='helloworld!';
    2 print_r(str_split($str,2));
    3 echo '<br>';
    4 print_r(str_split($str));

            输出结果:

           Array ( [0] => he [1] => ll [2] => ow [3] => or [4] => ld [5] => ! ) 
           Array ( [0] => h [1] => e [2] => l [3] => l [4] => o [5] => w [6] => o [7] => r [8] => l [9] => d [10] => ! )

           2.字符串反转函数strrev($str),将字符串倒序返回

    $str='hello world';
    echo strrev($str);

            输出结果:dlrow olleh

           3.chunk_split($str,length,$s),将str分割成length长度的子字符串,并在后面添加字符串s,最后连接起来返回新字符串

    $str='language';
    echo chunk_split($str,2,',');

           输出结果:la,ng,ua,ge,

           4.移除左侧字符函数ltrim($str,$s),从$str的左侧移除$s

    $str='helloworld';
    $s='hello';
    echo ltrim($str,$s);

           输出结果:world

           5.字符串转换成大写函数strtoupper($str)和转换成小写函数strtolower($str)

    $str='hello world';
    $str1=strtoupper($str);
    echo $str1,'<br>';
    $str2=strtolower($str1);
    echo $str2;

           输出结果:

           HELLO WORLD
           hello world

  • 相关阅读:
    [Codechef Coders' Legacy 2018 CLSUMG]Sum of Primes
    [HDU4630]No Pain No Game
    [Luogu4329][COCI2006]Bond
    [数论]Gcd/ExGcd欧几里得学习笔记
    [数论]线性基学习笔记
    [Luogu5190][COCI2010]PROGRAM
    IIS7 HTTPS 绑定主机头,嘿嘿,转
    React
    ios
    iOS10 权限配置
  • 原文地址:https://www.cnblogs.com/houtaoliang/p/4758130.html
Copyright © 2011-2022 走看看