Usage example of substr string interception function in php

WBOY
Release: 2016-07-25 08:58:46
Original
1283 people have browsed it
  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。



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!