note 34513 deleted from function.array-slice by didou

From: Date: Tue, 29 Jul 2003 17:31:04 +0000
Subject: note 34513 deleted from function.array-slice by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52952@lists.php.net to get a copy of this message
Note Submitter: eric ---- I'm new at this, and I didn't get any help from my friend Ryan, but this works great for breaking a string up into fractions. I used it for creating faux columns from one string on an html page. Enjoy! function fraction_words($numerator,$denominator,$string){ $string_as_array = explode(" ",$string); $wordcount = str_word_count($string); $offset = ceil((($wordcount/$denominator)*$numerator) - ($wordcount/$denominator)); $length = ceil($wordcount/$denominator); $fraction_words = join(" ",array_slice($string_as_array,$offset,$length)); return $fraction_words; } echo fraction_words(1,4,$your_string); This will return the first fourth of $your_string. Anybody smart out there...please help me with my boolean logic for the offset calculation if it's redundant...

« previous php.notes (#52952) next »