PHP two functions: Generate serial number, string substitution

Source: Internet
Author: User
  1. /**

  2. * Serial Number generator
  3. Func:snmaker
  4. Param: $pre = ' '
  5. */
  6. function Snmaker ($pre = ") {
  7. $date = Date (' Ymd ');
  8. $rand = rand (1000000,9999999);
  9. $time = Mb_substr (Time (), 5, 5, ' utf-8 ');
  10. $serialNumber = $pre. $date. $time. $rand;
  11. echo strlen ($serialNumber). '
    ';
  12. return $serialNumber;
  13. }
  14. Echo Snmaker ();

  15. /**

  16. * Replace a part of a string with a specific character
  17. * @param str or int $str The string to be processed
  18. * @param str or int $to will be replaced by what string
  19. * @param int $start retain the first few characters
  20. * @param int $end retain the last few characters
  21. * url:http://bbs.it-home.org
  22. * DATE:2013/2/17
  23. */
  24. function hidestring ($str = ' Hello ', $to = ' * ', $start = 1, $end = 0) {
  25. $lenth = strlen ($str)-$start-$end;
  26. $lenth = ($lenth < 0)? 0: $lenth;
  27. $to = Str_repeat ($to, $lenth);
  28. $str = Substr_replace ($str, $to, $start, $lenth);
  29. return $str;
  30. }
  31. Echo hidestring ();
  32. ?>

Copy Code
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.