/[LeafOK_CVS]/fenglin/lib/str_process.inc.php
ViewVC logotype

Contents of /fenglin/lib/str_process.inc.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Sat Mar 1 09:02:28 2025 UTC (12 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.8: +17 -28 lines
Convert GB2312 to UTF-8

1 <?
2
3 function split_line($str,$prefix="",$width=76)
4 {
5 if ($width<=0)
6 return $str;
7
8 $result = "";
9 $len = mb_strlen($str,'UTF-8');
10 $prefix_len = mb_strlen($prefix,'UTF-8');
11
12 $line = $prefix;
13 $line_len = $prefix_len;
14 for($i=0;$i<$len;$i++)
15 {
16 $c = mb_substr($str,$i,1,'UTF-8');
17 $line.=$c;
18
19 // Each UTF-8 CJK character should use two character length for display
20 $line_len += (strlen($c) <= 2 ? 1 : 2);
21
22 if ($line_len >= $width)
23 {
24 $result .= ($line . "\n");
25 $line = $prefix;
26 $line_len = $prefix_len;
27 }
28 }
29 $result .= ($line . "\n");
30
31 return $result;
32 }
33
34 function str_process($str,$prefix="",$width=76)
35 {
36 $result = "";
37
38 $lines = explode("\n",str_replace("\r\n","\n",$str));
39
40 foreach($lines as $tmp => $line)
41 {
42 $result .= split_line($line,$prefix,$width);
43 }
44
45 return $result;
46 }
47
48 function str_b_lines($str,$max_line=1)
49 {
50 $result = "";
51 $l = 0;
52 $lines = explode("\n",str_replace("\r\n","\n",$str));
53 foreach($lines as $tmp => $line)
54 {
55 $result .= ($line."\n");
56 $l += (mb_strlen($line,'UTF-8')/128 + 1);
57 if ($l >= $max_line)
58 break;
59 }
60
61 return $result;
62 }
63
64 ?>

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1