php中有没有向右取字符串的函数?
就像excel里面的right一样。

解决方案 »

  1.   

    substr能向右取吗?它是类似以excel的MID函数啊
      

  2.   

    $str="abcdefg";$des=substr($str,0,3);//从$str的第一个字符开始,向右去3个字符,也就是"abc"$des=substr($str,-3,3);//从$str的倒数第三个字符开始,向右去3个字符,也就是"efg"
      

  3.   

    substr
    (PHP 3, PHP 4, PHP 5)substr -- Return part of a string
    Description
    string substr ( string string, int start [, int length] )
    substr() returns the portion of string specified by the start and length parameters. If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth. 例子 1. Basic substr() usage<?php
    echo substr('abcdef', 1);     // bcdef
    echo substr('abcdef', 1, 3);  // bcd
    echo substr('abcdef', 0, 4);  // abcd
    echo substr('abcdef', 0, 8);  // abcdef
    echo substr('abcdef', -1, 1); // f// Accessing single characters in a string
    // can also be achived using "curly braces"
    $string = 'abcdef';
    echo $string{0};                 // a
    echo $string{3};                 // d
    echo $string{strlen($string)-1}; // f?>  
     If start is negative, the returned string will start at the start'th character from the end of string. 例子 2. Using a negative start<?php
    $rest = substr("abcdef", -1);    // returns "f"
    $rest = substr("abcdef", -2);    // returns "ef"
    $rest = substr("abcdef", -3, 1); // returns "d"
    ?>  
     
    多看手册!