| 1 |
<? |
<? |
| 2 |
|
|
| 3 |
function split_line($str,$pre="",$width=75) |
function split_line($str,$prefix="",$width=75) |
| 4 |
{ |
{ |
| 5 |
$lines = array(); |
$lines = array(); |
| 6 |
$lines_count = 0; |
$lines_count = 0; |
| 7 |
$len = strlen($str); |
$len = strlen($str); |
| 8 |
|
|
| 9 |
$hz_ok = true; |
$hz_ok = true; |
|
$en_ok = true; |
|
| 10 |
|
|
| 11 |
if ($width<=0) |
if ($width<=0) |
| 12 |
return $str; |
return $str; |
| 13 |
|
|
| 14 |
$line = $pre; |
$line = $prefix; |
| 15 |
$line_count = strlen($line); |
$line_count = strlen($line); |
| 16 |
for($i=0;$i<$len;$i++) |
for($i=0;$i<$len;$i++) |
| 17 |
{ |
{ |
| 20 |
if (ord($str[$i])>127) |
if (ord($str[$i])>127) |
| 21 |
{ |
{ |
| 22 |
$hz_ok = (!$hz_ok); |
$hz_ok = (!$hz_ok); |
|
$en_ok = true; |
|
| 23 |
} |
} |
| 24 |
if (ord($str[$i])<=127) |
if (ord($str[$i])<=127) |
| 25 |
{ |
{ |
| 26 |
$hz_ok = true; |
$hz_ok = true; |
|
if ($str[$i] == " ") |
|
|
{ |
|
|
$en_ok = true; |
|
|
} |
|
|
else |
|
|
{ |
|
|
$en_ok = false; |
|
|
} |
|
| 27 |
} |
} |
| 28 |
if ($line_count >= $width && $hz_ok && $en_ok) |
if ($line_count >= $width && $hz_ok) |
| 29 |
{ |
{ |
| 30 |
$lines[$lines_count++] = $line; |
$lines[$lines_count++] = $line; |
| 31 |
$line = $pre; |
$line = $prefix; |
| 32 |
$line_count = strlen($line); |
$line_count = strlen($line); |
| 33 |
} |
} |
| 34 |
} |
} |
| 42 |
return $result; |
return $result; |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
function str_process($str,$pre="",$width=75) |
function str_process($str,$prefix="",$width=75) |
| 46 |
{ |
{ |
| 47 |
$result = ""; |
$result = ""; |
| 48 |
|
|
| 50 |
|
|
| 51 |
foreach($lines as $line) |
foreach($lines as $line) |
| 52 |
{ |
{ |
| 53 |
$result .= split_line($line,$pre,$width); |
$result .= split_line($line,$prefix,$width); |
| 54 |
} |
} |
| 55 |
|
|
| 56 |
return $result; |
return $result; |