// Copyright: Copyright (C) 2004-2007 Pristine Communications // split_long_lines: Split long lines (English only) function split_long_lines($source, $line_width) { $pos = 0; $result = ""; while (preg_match("/^(\S+[^\n\S]*|[^\n\S]+|\n+)/s", $source, $m)) { $piece = $m[1]; // Text token if (preg_match("/^\S/", $piece)) { // Split line if ($pos + strlen($piece) > $line_width) { $result .= "\n"; $pos = 0; } $result .= $piece; $pos += strlen($piece); // Space token -- skip if over $line_width } elseif (preg_match("/^[^\n\S]/", $piece)) { // Split line if ($pos + strlen($piece) > $line_width) { $result .= "\n"; $pos = 0; } else { $result .= $piece; $pos += strlen($piece); } // New-line token -- add it and reset the position } else { $result .= $piece; $pos = 0; } $source = substr($source, strlen($piece)); } return $result; } ?>