Home  >  Article  >  Backend Development  >  Usage example of substr string interception function in php

Usage example of substr string interception function in php

WBOY
WBOYOriginal
2016-07-25 08:58:461307browse
  1. //by bbs.it-home.org
  2. $rest = substr("abcdef", 1); // returns "bcdef"
  3. echo 'substr("abcdef", 1) returns ' . $rest . "
    ";
  4. $rest = substr("abcdef", 1, 3); // returns "bcd"
  5. echo 'substr("abcdef", 1, 3) returns ' . $rest . "
    ";
  6. $rest = substr("abcdef", -1); // returns "f"
  7. echo 'substr("abcdef", -1) returns ' . $rest . "
    ";
  8. $rest = substr("abcdef", -2); // returns "ef"
  9. echo 'substr("abcdef", -2) returns ' . $rest . "
    ";
  10. $rest = substr("abcdef", -3, 1); // returns "d"
  11. echo 'substr("abcdef", -3, 1) returns ' . $rest . "
    ";
  12. $rest = substr("abcdef", 1, -1); // returns "bcde"
  13. echo 'substr("abcdef", 1, -1) returns ' . $rest . "
    ";
  14. ?>
复制代码

更多内容,请参考php手册中的function.substr.html。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn