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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.8 by sysadm, Wed Apr 27 12:54:57 2005 UTC Revision 1.9 by sysadm, Sat Mar 1 09:02:28 2025 UTC
# Line 2  Line 2 
2    
3  function split_line($str,$prefix="",$width=76)  function split_line($str,$prefix="",$width=76)
4  {  {
         $lines = array();  
         $lines_count = 0;  
         $len = strlen($str);  
   
         $hz_ok = true;  
           
5          if ($width<=0)          if ($width<=0)
6                  return $str;                  return $str;
7                    
8            $result = "";
9            $len = mb_strlen($str,'UTF-8');
10            $prefix_len = mb_strlen($prefix,'UTF-8');
11    
12          $line = $prefix;          $line = $prefix;
13          $line_count = strlen($line);          $line_len = $prefix_len;
14          for($i=0;$i<$len;$i++)          for($i=0;$i<$len;$i++)
15          {          {
16                  $line.=$str[$i];                  $c = mb_substr($str,$i,1,'UTF-8');
17                  $line_count++;                  $line.=$c;
18                  if (ord($str[$i])>127)  
19                  {                  // Each UTF-8 CJK character should use two character length for display
20                          $hz_ok = (!$hz_ok);                  $line_len += (strlen($c) <= 2 ? 1 : 2);
21                  }  
22                  if (ord($str[$i])<=127)                  if ($line_len >= $width)
                 {  
                         $hz_ok = true;  
                 }  
                 if ($line_count >= $width && $hz_ok)  
23                  {                  {
24                          $lines[$lines_count++] = $line;                          $result .= ($line . "\n");
25                          $line = $prefix;                          $line = $prefix;
26                          $line_count = strlen($line);                          $line_len = $prefix_len;
27                  }                  }
28          }          }
29          $lines[$lines_count++] = $line;          $result .= ($line . "\n");
30    
         $result = "";  
         for($i=0;$i<$lines_count;$i++)  
         {  
                 $result.=($lines[$i]."\r\n");  
         }  
31          return $result;          return $result;
32  }  }
33    
# Line 63  function str_b_lines($str,$max_line=1) Line 52  function str_b_lines($str,$max_line=1)
52          $lines = explode("\n",str_replace("\r\n","\n",$str));          $lines = explode("\n",str_replace("\r\n","\n",$str));
53          foreach($lines as $tmp => $line)          foreach($lines as $tmp => $line)
54          {          {
55                  $result .= ($line."\r\n");                  $result .= ($line."\n");
56                  $l += (strlen($line)/256 + 1);                  $l += (mb_strlen($line,'UTF-8')/128 + 1);
57                  if ($l >= $max_line)                  if ($l >= $max_line)
58                          break;                          break;
59          }          }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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