[cvs] / gkbweb / htdocs / shared / inc / wordwrap.inc  

cvs: gkbweb/htdocs/shared/inc/wordwrap.inc

File: [cvs] / gkbweb / htdocs / shared / inc / wordwrap.inc (download)
Revision: 1.1.1.1 (vendor branch), Wed Jul 21 17:43:42 2004 UTC (8 years, 10 months ago) by tmcnulty
Branch: MAIN, ppckernel
CVS Tags: release1, HEAD
Changes since 1.1: +0 -0 lines
Imported from old repository on hercules.  Removed passwords from source.

<?php
if (!isset($xorsis_include_wordwrap)) {
    
$xorsis_include_wordwrap=1;
/* word_wrap($string, $cols, $prefix)
 *
 * Takes $string, and wraps it on a per-word boundary (does not clip
 * words UNLESS the word is more than $cols long), no more than $cols per
 * line. Allows for optional prefix string for each line. (Was written to
 * easily format replies to e-mails, prefixing each line with "> ".
 *
 * Copyright 1999 Dominic J. Eidson, use as you wish, but give credit
 * where credit due.
 */
    
function word_wrap ($string$cols 80$prefix "") {

    
$t_lines split"\n"$string);
        
$outlines "";

    while(list(, 
$thisline) = each($t_lines)) {
        if(
strlen($thisline) > $cols) {

            
$newline "";
            
$t_l_lines split(" "$thisline);
    
            while(list(, 
$thisword) = each($t_l_lines)) {
                while((
strlen($thisword) + strlen($prefix)) > $cols) {
                    
$cur_pos 0;
                    
$outlines .= $prefix;
        
                    for(
$num=0$num $cols-1$num++) {
                        
$outlines .= $thisword[$num];
                        
$cur_pos++;
                    }
        
                    
$outlines .= "\n";
                    
$thisword substr($thisword$cur_pos, (strlen($thisword)-$cur_pos));
                }
    
                if((
strlen($newline) + strlen($thisword)) > $cols) {
                    
$outlines .= $prefix.$newline."\n";
                    
$newline $thisword." ";
                } else {
                    
$newline .= $thisword." ";
                }
            }
    
            
$outlines .= $prefix ltrim($newline) . "\n";
        } else {
            
$outlines .= $prefix ltrim($thisline) . "\n";
        }
    }
    return 
$outlines;
    }
}
?>

Tobias McNulty

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help