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.