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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Jun 25 06:49:15 2004 UTC (21 years, 8 months ago) by sysadm
Branch: MAIN
Improve auto new line with HZ

1 sysadm 1.1 <?
2    
3     function split_line($str,$width=75,$pre="")
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 = $pre;
15     $line_count = strlen($line);
16     for($i=0;$i<$len;$i++)
17     {
18     if ($line_count >= $width && $hz_ok)
19     {
20     $lines[$lines_count++] = $line;
21     $line = $pre;
22     $line_count = strlen($line);
23     }
24     $line.=$str[$i];
25     $line_count++;
26     if (ord($str[$i])>127)
27     $hz_ok = (!$hz_ok);
28     if (ord($str[$i])<=127)
29     $hz_ok = true;
30     }
31     $lines[$lines_count++] = $line;
32    
33     $result = "";
34     for($i=0;$i<$lines_count;$i++)
35     {
36     $result.=($lines[$i]."\r\n");
37     }
38     return $result;
39     }
40    
41     function add_colon($str,$width=75)
42     {
43     $result = "";
44    
45     $lines = explode("\n",str_replace("\r\n","\n",$str));
46    
47     foreach($lines as $line)
48     {
49     $result .= split_line($line,$width,": ");
50     }
51    
52     return $result;
53     }
54    
55     ?>

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