Discussion on the specific way of PHP split string _php Tutorial

Source: Internet
Author: User
We are usingResult: Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4)

Definition and usage
The Str_split () function splits a string into an array.

Syntax length indicates the number of each string

Str_split (string,length) The default length is 1 above if it is Str_split ($STR, 2) result for array ([0] = [1] = 34)

If it is $str= ' 1 2 3 4 ' This time use explode () function explode (", $str) separated by spaces

If the content of an article is truncated by the number of characters: Use the strlen () function and the substr () string intercept function to implement the PHP split string function, such as:

 
  
  
  1. < ? PHP $ len = strlen ( $row [' Game_detail ']);
  2. //Gets the length of the string;
  3. if ($len 102)
  4. //judgment string if it is greater than 102, the output of 102 strings.
  5. {echo $ s = substr ($row [' Game_detail '],
    0,102), echo ' ... ';
  6. }
  7. else{echo $row ["Game_detail"];
  8. //otherwise output all;
  9. }
  10. ?>< /span>

That is, make a judgment before the output. strlen (string name): substr (String, 0,102) the range to be divided by 0-103. These are all the methods of PHP split string, I hope you have some control.


http://www.bkjia.com/PHPjc/446237.html www.bkjia.com true http://www.bkjia.com/PHPjc/446237.html techarticle we are using the result: Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4) define and use the Str_split () function to divide a string into an array. Syntax length indicates the number of each string ...

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