|
|
|
//Algorithm contributed by Richard Lynch at <lynch@lscorp.com>
Function fill_paragraphs($text, $wrap=80, $break="\n") {
// break the text into paragraphs by stripping off any newline characters
$paragraphs = split("\n+", "$text");
// format one paragraph at a time
for ($i = 0; $i < sizeof($paragraphs); $i++) {
$paragraphs[$i] = textwrap($paragraphs[$i], $wrap, $break);
}
// concatenate the formatted paragraphs into a single string
// with a newline character between each element
return implode("\n", $paragraphs);
}
// Contributed by Richard Lynch: <lynch@lscorp.com>.
Function textwrap($text, $wrap=80, $break="\n"){
$len = strlen($text);
if ($len > $wrap){
$h = ''; // massaged text
$lastWhite = 0; // position of last whitespace char
$lastChar = 0; // position of last char
$lastBreak = 0; // position of last break
// while there is text to process
while ($lastChar < $len){
$char = substr($text, $lastChar, 1); // get the next character
// if we are beyond the wrap boundry and there is a place to break
if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)){
$h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break;
$lastChar = $lastWhite + 1;
$lastBreak = $lastChar;
}
// You may wish to include other characters as valid whitespace...
if ($char == ' ' || $char == chr(13) || $char == chr(10)){
$lastWhite = $lastChar; // note the position of the last white space
}
$lastChar = $lastChar + 1; // advance the last character position by one
}
$h .= substr($text, $lastBreak); // build line
}
else{
$h = $text; // in this case everything can fit on one line
}
return $h;
}
|
|
| The Porter Word Stemming Algorithm in PHP
Reduces words to their base stem for search engines and indexing Categories : Algorithms, PHP, Strings | | | textwrap fill-paragraph (justification) Categories : Strings, PHP, Algorithms | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | mysql_escape_string Categories : PHP, MySQL, Databases, Strings | | | Allows you to parse a deliniated string and put the individual fields in a SELECT option in a form Categories : HTML, PHP, Strings | | | function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP | | | Adding dashes to credit card numbers Categories : Strings, Credit Cards, PHP | | | Boolean Keyword Interpreter Categories : PHP, Algorithms, Search Engines | | | I need a trim function/regexp that will trim all " " from the ends of a string. Categories : Regexps, PHP, Strings | | | Diffusion-Limited Aggregation visualization Categories : PHP, Graphics, Algorithms, Math. | | | Customizable encoding and decoding strings with security. Categories : PHP, Strings, HTML and PHP | | | Printer friendly pages from anywhere on a website. Categories : PHP, Strings, Content Management | | | Browse a MySQL database & draw a tree view & load final items into a template page. Categories : MySQL, Complete Programs, Algorithms, PHP, Databases | | | Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms | |
|
|
|