zoukankan      html  css  js  c++  java
  • php中trim()的特殊用法

    以前用asp时只知道trim()可以去除字符串两边的空格,今天在php中发现trim()还有如下功能:

    这是php手册中的例子

    例 2321. Usage example of rtrim()

    <?php

    $text 
    "\t\tThese are a few words :) ...  ";
    $binary "\x09Example string\x0A";
    $hello  "Hello World";
    var_dump($text$binary$hello);

    print 
    "\n";

    $trimmed rtrim($text);
    var_dump($trimmed);

    $trimmed rtrim($text" \t.");
    var_dump($trimmed);

    $trimmed rtrim($hello"Hdle");
    var_dump($trimmed);

    // trim the ASCII control characters at the end of $binary
    // (from 0 to 31 inclusive)
    $clean rtrim($binary"\x00..\x1F");
    var_dump($clean);

    ?>

    上例将输出:

    string(32) "        These are a few words :) ...  "
    string(16) "    Example string
    "
    string(11) "Hello World"
    string(30) "        These are a few words :) ..."
    string(26) "        These are a few words :)"
    string(9) "Hello Wor"
    string(15) "    Example string"
    

    除了以上外还可以这样用

    如:$a='|a|b|c|';

    echo trim($a,'|');

    输出结果为:a|b|c

  • 相关阅读:
    Google验证码Kaptcha的详细过程
    stm32—单总线(1-wire)
    stm32—I2C
    归并排序(MergeSort)
    冒泡排序(Bubble Sort)
    stm32—GPIO
    stm32—时钟系统
    stm32—复位
    转义字符表
    ASCII码表格
  • 原文地址:https://www.cnblogs.com/wbcms/p/1388870.html
Copyright © 2011-2022 走看看