string handling
|string to columns
| see demonstration of string to columnsthis will "columnize" your long text.
long text, especially on large screens is really hard to read.
thats why in the "real world" newspapers use columns to layout text.
with this script you just paste the text and specify the numbers of columns.
it will split the text into more reader-friendly chunks.
full source of string to columns [ line 1 - 67 ] | download string to columns
| 1 | <?php |
| 2 | $marginpercent = 3; |
| 3 | $topmarginpx = 200; |
| 4 | $bgcolor = 'whitesmoke'; |
| 5 | $paddingpx = 5; |
| 6 | $seperators = array(' ' => 'words', '. ' => 'sentences', '<p>' => 'paragraphs'); |
| 7 | if($_POST['string']) |
| 8 | { |
| 9 | if($_POST['column']) $columns = $_POST['column']; |
| 10 | else $columns = 3; |
| 11 | if($_POST['seperator']) $seperator = $_POST['seperator']; |
| 12 | else $seperator = ' '; |
| 13 | $widthpercent = ceil(((100-(2*$marginpercent))/$columns)-2); |
| 14 | $stringlen = strlen($_POST['string']); |
| 15 | $percolumn = ceil($stringlen/$columns); |
| 16 | for($x = 0; $x < $columns; $x++) |
| 17 | { |
| 18 | $leftpx = (($x*ceil((100-(2*$marginpercent))/$columns))+$marginpercent); |
| 19 | $string = stripcslashes(substr($_POST['string'],($percolumn*$x),$percolumn)); |
| 20 | $nextstring = stripcslashes(substr($_POST['string'],($percolumn*($x+1)),$percolumn)); |
| 21 | $nextpos = strpos(strtolower($nextstring),strtolower($seperator)); |
| 22 | $nextword = substr($nextstring,0,($nextpos+strlen($seperator))); |
| 23 | $string = substr($string,$oldpos,$percolumn); |
| 24 | $string = $string.$nextword; |
| 25 | $oldpos = $nextpos+strlen($seperator); |
| 26 | echo ' |
| 27 | <div style="position:absolute; |
| 28 | left:'.$leftpx.'%; |
| 29 | top:'.$topmarginpx.'px; |
| 30 | padding:'.$paddingpx.'px; |
| 31 | width:'.$widthpercent.'%; |
| 32 | background-color:'.$bgcolor.';"> |
| 33 | '; |
| 34 | if($x > 0 && $_POST['heightpx']) echo ' |
| 35 | <div style="height:'.$_POST['heightpx'].'px; width:'.$widthpercent.'%;"> </div>'; |
| 36 | echo $string; |
| 37 | echo ' |
| 38 | </div> |
| 39 | '; |
| 40 | } |
| 41 | }else{ |
| 42 | echo ' |
| 43 | <div style="position:absolute; |
| 44 | left:'.$marginpercent.'%; |
| 45 | top:'.$topmarginpx.'px; |
| 46 | padding:'.$paddingpx.'px; |
| 47 | width:'.(100-(2*$marginpercent)).'%; |
| 48 | background-color:'.$bgcolor.';"> |
| 49 | <form method="post" action="'.$_SERVER['PHP_SELF'].'"> |
| 50 | <textarea name="string" cols="70" rows="20"></textarea><br /> |
| 51 | <input type="text" name="column" value="3" size="3" /> columns | text split at |
| 52 | <input type="text" name="seperator" size="3" /> |
| 53 | <select name="preset" onchange="seperator.value=this.value">'; |
| 54 | foreach($seperators as $k => $v) |
| 55 | { |
| 56 | echo ' |
| 57 | <option value="'.$k.'">'.$v.'</option>'; |
| 58 | } |
| 59 | echo ' |
| 60 | </select> | |
| 61 | <input type="text" name="heightpx" value="" size="3" /> topmargin on column 1+ | |
| 62 | <input type="submit" value="columnize" /> |
| 63 | </form> |
| 64 | </div> |
| 65 | '; |
| 66 | } |
| 67 | ?> |
41 hits by 13 users in the last 30 minutes.