/[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.8 - (show annotations)
Wed Apr 27 12:54:57 2005 UTC (20 years, 10 months ago) by sysadm
Branch: MAIN
CVS Tags: fenglin_1-0-0-0_MIL
Changes since 1.7: +2 -2 lines
Change max length of line

1 <?
2
3 function split_line($str,$prefix="",$width=76)
4 {
5 $lines = array();
6 $lines_count = 0;
7 $len = strlen($str);
8
9 $hz_ok = true;
10
11 if ($width<=0)
12 return $str;
13
14 $line = $prefix;
15 $line_count = strlen($line);
16 for($i=0;$i<$len;$i++)
17 {
18 $line.=$str[$i];
19 $line_count++;
20 if (ord($str[$i])>127)
21 {
22 $hz_ok = (!$hz_ok);
23 }
24 if (ord($str[$i])<=127)
25 {
26 $hz_ok = true;
27 }
28 if ($line_count >= $width && $hz_ok)
29 {
30 $lines[$lines_count++] = $line;
31 $line = $prefix;
32 $line_count = strlen($line);
33 }
34 }
35 $lines[$lines_count++] = $line;
36
37 $result = "";
38 for($i=0;$i<$lines_count;$i++)
39 {
40 $result.=($lines[$i]."\r\n");
41 }
42 return $result;
43 }
44
45 function str_process($str,$prefix="",$width=76)
46 {
47 $result = "";
48
49 $lines = explode("\n",str_replace("\r\n","\n",$str));
50
51 foreach($lines as $tmp => $line)
52 {
53 $result .= split_line($line,$prefix,$width);
54 }
55
56 return $result;
57 }
58
59 function str_b_lines($str,$max_line=1)
60 {
61 $result = "";
62 $l = 0;
63 $lines = explode("\n",str_replace("\r\n","\n",$str));
64 foreach($lines as $tmp => $line)
65 {
66 $result .= ($line."\r\n");
67 $l += (strlen($line)/256 + 1);
68 if ($l >= $max_line)
69 break;
70 }
71
72 return $result;
73 }
74
75 ?>

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