The following describes two php string truncation functions. The method is simple: string to be captured, the length of sublen, and the starting position of $ start. The following describes two php string truncation functions. The method is simple: string to be captured, the length of sublen, and the starting position of $ start.
Script ec (2); script
| The Code is as follows: |
|
|
Function my_sub_str ($ string, $ sublen, $ start)
{
$ Pa = "/fdddd ";
Preg_match_all ($ pa, $ string, $ t_string );
If (count ($ t_string [0])-$ start> $ sublen) return join ('', array_slice ($ t_string [0], $ start, $ sublen )). "... ";
Return join ('', array_slice ($ t_string [0], $ start, $ sublen ));
} |
/**
* String truncation "..."
*/
| The Code is as follows: |
|
|
Function my_sub_str_00 ($ string, $ sublen, $ start)
{
$ Pa = "/sss /";
Preg_match_all ($ pa, $ string, $ t_string );
Return join ('', array_slice ($ t_string [0], $ start, $ sublen ));
} |
// Character truncation Test
| The Code is as follows: |
|
$ String = "www.111cn.net China web First stop ";
Echo my_sub_str ($ string, 10, 0); // output www.111cn .... |