|
|
|
<?php
function textwrap($text, $wrap=80, $break='<BR>\n'){
$len = strlen($text);
if ($len > $wrap){
$h = '';
$lastWhite = 0;
$lastChar = 0;
$lastBreak = 0;
while ($lastChar < $len){
$char = substr($text, $lastChar, 1);
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;
}
$lastChar = $lastChar + 1;
}
$h .= substr($text, $lastBreak);
}
else{
$h = $text;
}
return $h;
}
?>
<HTML>
<HEAD><TITLE>Textwrap Example</TITLE></HEAD>
<BODY>
<?php
$test = "This is a test. This is only a test. Had
this been a real emergency you would have been instructed to put your head
between your knees and pray.";
echo("$test<BR>\n<BR>\n");
for ($w = 80; $w > 0; $w = $w - 10){
$wrapped = textwrap($test, $w);
echo("$w<BR>\n$wrapped<BR>\n<BR>\n");
}
?>
</BODY>
</HTML>
|
|
| Customizable encoding and decoding strings with security. Categories : PHP, Strings, HTML and PHP | | | Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP, PHP, Strings | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Text Wrapping Categories : PHP, HTML and PHP, Strings | | | string justification align center text Categories : Strings, PHP, HTML and PHP | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | A simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables | | | phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install. Categories : PHP, Complete Programs, HTML and PHP, MySQL | | | Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS) | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Calendar using Date function Categories : HTML and PHP, PHP, Date Time, Calendar | | | PageRank Display Categories : Search Engines, HTML and PHP, PHP | | | PHP, simple, counter, bala Categories : HTML and PHP, PHP, PHP Options and Info | | | explode() and SQL blobs Categories : General SQL, Strings, PHP, Databases | |
|
|
|