Master teaches you PHP string intercept function using _php tutorial

Source: Internet
Author: User
When learning PHP, you may encounter PHP string interception problem, here will introduce the PHP string interception function problem resolution, here to share with you. PHP itself is a simple and powerful language. The PHP language has core features such as powerful string and array processing capabilities, while greatly improving the support for object-oriented programming (PHP5 and above).

By using standard and optional extensions, PHP applications can connect more than 10 databases such as MySQL or Oracle, draw, create PDF files, and create parsing XML files. You can also use the C language to write your own PHP extension module. For example, provide an interface function for PHP in a code base that already exists. You can also run PHP under Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to a database. At home, PHP once and Microsoft's ASP, is commonly used in network programming language.

ASP3.0 now has been abandoned by Microsoft, no longer updated, perhaps some people will think: PHP should be a fast-dying thing, right? However, contrary to the fact, PHP not only in the rapid development, the ASP far behind, and gradually become the Internet is now the most widely used, the most popular language. Let's use PHP as a powerful language to solve this problem.

PHP string intercept function code:

 
 
  1. PHP
  2. Functionget_substr ($string, $start=' 0 ', $length= '' )
  3. {
  4. $ Start = (int) $start;
  5. $ length = (int) $length;
  6. $ I = 0 ;
  7. if (! $string)
  8. {
  9. Return
  10. }
  11. if ($start>=0)
  12. {
  13. While ($i<$start)
  14. {
  15. if (Ord ($string [$i])>127)
  16. {
  17. $ I = $i +2;
  18. }
  19. Else
  20. {
  21. $i + +;
  22. }
  23. }
  24. $ Start = $i;
  25. if ($length= = ")
  26. {
  27. Returnsubstr ($string, $start);
  28. }
  29. ElseIf ($length>0)
  30. {
  31. $ End = $start + $length;
  32. While ($i<$end)
  33. {
  34. if (Ord ($string [$i])>127)
  35. {
  36. $ I = $i +2;
  37. }
  38. Else
  39. {
  40. $i + +;
  41. }
  42. }
  43. if ($end! = $i-1)
  44. {
  45. $ End = $i;
  46. }
  47. Else
  48. {
  49. $end--;
  50. }
  51. $ length = $end-$start;
  52. Returnsubstr ($string, $start, $length);
  53. }
  54. ElseIf ($length==0)
  55. {
  56. Return
  57. }
  58. Else
  59. {
  60. $ length = strlen ($string)-abs ($length)-$start;
  61. Returnget_substr ($string, $start, $length);
  62. }
  63. }
  64. Else
  65. {
  66. $ Start = strlen ($string)-abs ($start);
  67. Returnget_substr ($string, $start, $length);
  68. }
  69. }
  70. ?>

http://www.bkjia.com/PHPjc/446451.html www.bkjia.com true http://www.bkjia.com/PHPjc/446451.html techarticle When learning PHP, you may encounter PHP string interception problem, here will introduce the PHP string interception function problem resolution, here to share with you. PHP itself is a ...

  • 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.