zoukankan      html  css  js  c++  java
  • 10.1、字符串格式化

     
     PHP Code By http://t.qq.com/tony-src
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    <?php 
        
        /**
         * 清理空格
         */

        $str = 
    '          PHP            ';
        
    echo ltrim($str);   // 去左边空格
        echo rtrim($str);   // 去右边空格,chop() 为rtrim()别名
        echo trim($str);    // 清理左右空格
        
        
    /**
         * 将换行符换成<br>
         */

        $str = 
    "This is a Teacher!\n This is Student";
        
    echo nl2br($str);
        
        
    /**
         * 所有字符转换成 HTML
         */

        $str = 
    '<strong>张三</strong>';
        
    echo htmlentities($str);
        
        
    /**
         * 转换特殊字符转换成 HTML
         */

        $str = 
    '<strong>张三</strong>';
        
    echo htmlspecialchars($str);
        
        
    /**
         * 去除 HTML 标记
         */

        $str = 
    '<strong>张三</strong>';
        
    echo strip_tags($str);
        
        
    /**
         * 转义字符串
         */

        $str = 
    'This is a Teacher.His is a "tony",\n This is tony wang';
        
    echo $string = addslashes($str);
        
        
    /**
         * 反转义字符串
         */

        
    echo $string;
        
    echo stripslashes($string);
        
        
    /**
         * 字符串转换
         */

        
    echo strtoupper('tony');                // 转换成大写
        echo strtolower('TONY');                // 转换成小写
        echo ucfirst('tony');                   // 将第一个字母转换为大写
        echo ucwords('my name is tony!');       // 将每个单词第一个字母转换为大写
        
        $str = 
    'tony';
        
    echo str_pad($str, 10).'is good!';      // 字符串填充
        echo str_pad($str, 10,'#');             // 填充指定的内容
        echo str_pad($str, 10,STR_PAD_LEFT);    // 填充方向
        
    ?>




  • 相关阅读:
    Appium学习实践(二)Python简单脚本以及元素的属性设置
    Appium学习实践(三)测试用例脚本以及测试报告输出
    Appium学习实践(一)简易运行Appium
    Appium学习实践(四)结构优化
    js中对小数取整的函数
    C#基础 面试中常出现的问题
    repeater中的删除按钮实现
    js对fck编辑器取值 赋值
    jQuery对select操作
    进制转换(二进制 八进制 十进制 十六进制)
  • 原文地址:https://www.cnblogs.com/tonycody/p/2808237.html
Copyright © 2011-2022 走看看