1 |
jonen |
1.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 |
jonen |
1.2 |
function my_nl2br($raw_string, $class=NULL) { |
18 |
jonen |
1.1 |
|
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 |
jonen |
1.2 |
$div->add( $lines[$index], html_br() ); |
31 |
jonen |
1.1 |
$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 |
jonen |
1.2 |
"action" => $_SERVER["PHP_SELF"])); |
42 |
jonen |
1.1 |
|
43 |
|
|
|
44 |
jonen |
1.2 |
$textarea = form_textarea("text", "this is a lame test" ); |
45 |
jonen |
1.1 |
$textarea->set_tag_attributes( array("cols" => "60", |
46 |
|
|
"rows" => "40") ); |
47 |
|
|
|
48 |
jonen |
1.2 |
$form->add( html_br(), $textarea, html_br() ); |
49 |
jonen |
1.1 |
|
50 |
jonen |
1.2 |
$form->add( form_submit("what", "Submit") ); |
51 |
|
|
$form->add( form_submit("debug", "Debug") ); |
52 |
jonen |
1.1 |
|
53 |
jonen |
1.2 |
$page->add( $form, html_br(), html_br() ); |
54 |
jonen |
1.1 |
|
55 |
jonen |
1.2 |
if ($_SERVER["REQUEST_METHOD"] == "POST") { |
56 |
jonen |
1.1 |
//Ok lets process the input. |
57 |
jonen |
1.2 |
$div = my_nl2br( $_POST["text"] ); |
58 |
|
|
$page->add( $div ); |
59 |
jonen |
1.1 |
} |
60 |
|
|
|
61 |
|
|
print $page->render(); |
62 |
|
|
?> |