| 1 | <?php | 
| 2 |  | 
| 3 | include_once("localinc.php"); | 
| 4 |  | 
| 5 | /** | 
| 6 | * This function parses the input string and | 
| 7 | * replaces all occurences of a \n character | 
| 8 | * with a BRtag object.  Then it wraps the entire | 
| 9 | * new string with a DIVtag object with a | 
| 10 | * class reference of $class. | 
| 11 | * | 
| 12 | * @param   string  $raw_string - the input string. | 
| 13 | * @param   string  $class - the css class to give | 
| 14 | *                           to the wrapper DIVtag | 
| 15 | * @return  DIVtag object. | 
| 16 | */ | 
| 17 | function my_nl2br($raw_string, $class=NULL) { | 
| 18 |  | 
| 19 | $attributes = array(); | 
| 20 | if ($class) { | 
| 21 | $attributes = array ("class" => $class ); | 
| 22 | } | 
| 23 | $div = new DIVtag( $attributes ); | 
| 24 |  | 
| 25 | //Ok now lets walk through the string | 
| 26 | //and find each \n char. | 
| 27 | $lines = explode( chr(13), $raw_string); | 
| 28 | $index=0; | 
| 29 | while( $lines[$index] ) { | 
| 30 | $div->add( $lines[$index], html_br() ); | 
| 31 | $index++; | 
| 32 | } | 
| 33 | return $div; | 
| 34 | } | 
| 35 |  | 
| 36 | $page = new HTMLPageClass("test.php"); | 
| 37 | $page->set_text_debug( $debug ); | 
| 38 |  | 
| 39 | $form = new FORMtag(array("name"=> "testform", | 
| 40 | "method" => "POST", | 
| 41 | "action" => $_SERVER["PHP_SELF"])); | 
| 42 |  | 
| 43 |  | 
| 44 | $textarea = form_textarea("text", "this is a lame test" ); | 
| 45 | $textarea->set_tag_attributes( array("cols" => "60", | 
| 46 | "rows" => "40") ); | 
| 47 |  | 
| 48 | $form->add( html_br(), $textarea, html_br() ); | 
| 49 |  | 
| 50 | $form->add( form_submit("what", "Submit") ); | 
| 51 | $form->add( form_submit("debug", "Debug") ); | 
| 52 |  | 
| 53 | $page->add( $form, html_br(), html_br() ); | 
| 54 |  | 
| 55 | if ($_SERVER["REQUEST_METHOD"] == "POST") { | 
| 56 | //Ok lets process the input. | 
| 57 | $div = my_nl2br( $_POST["text"] ); | 
| 58 | $page->add( $div ); | 
| 59 | } | 
| 60 |  | 
| 61 | print $page->render(); | 
| 62 | ?> |