How to intercept Chinese strings in cakephp

Source: Internet
Author: User
How can I intercept Chinese strings in cakephp? I thought I had to write helper to intercept Chinese strings. I didn't expect the truncate method to be provided in the Texthelper class of cakephp. The following is a prototype of the truncate method. Reference truncate & nbsp; how does trunc intercept Chinese strings in cakephp?
I thought I had to write helper to intercept Chinese strings. I didn't expect the truncate method to be provided in the Text helper class of cakephp. The following is a prototype of the truncate method.

Reference truncate
Truncate (string $ text, int $ length = 100, array $ options)
Cuts a string to the $ length and adds a suffix with 'ending' if the text is longer than $ length. if 'delete' is passed as false, the truncation will occur after the next word ending. if 'html' is passed as true, html tags will be respected and will not be cut off.

The Text-> truncate method has three parameters:

  • $ Text: string to be truncated
  • $ Length: the length to be intercepted. the default value is 100 characters.
  • $ Options: array parameter. Ending indicates adding the ending string to the end of the intercepted string. if the value of exact is false, the word is not truncated. if the value of html is true, the html tag is not truncated.

The following code demonstrates how to use the tuncate method:

echo $this->Text->truncate(    'The killer crept forward and tripped on the rug.',    22,    array(        'ending' => '...',        'exact' => false    ));


The above code will be output The killer crept...
Note: If you want to intercept Chinese strings, it is best to set exact to true. Otherwise, Chinese characters cannot be truncated.

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.