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