Simple (??) control structure problem

From: Date: Sun, 15 Jul 2001 18:01:09 +0000
Subject: Simple (??) control structure problem
Groups: php.general 
Request: Send a blank email to php-general+get-57977@lists.php.net to get a copy of this message
I'm trying to write a simple weblog script, but I've encountered a perplexing problem. I'm sure I'm overlooking something simple. I'm trying to take <textarea> form input, parse it, and wrap it in <p> tags. The problem is removing extra carriage returns. I'm sure there's a problem with the "if ($sentence != ' ')", but I don't know what the right conditional statement is. No matter what I put in there, it keeps processing any extra blank lines and putting an extra pair of "<p></p>" tags in. Granted, this doesn't effect the way the page is displayed. For correctness sake, I'd rather not have them in there. Here's the simple page I threw together to illustrate the problem: <html> <body> <?php if ($submit) { $funk = explode("\n", $paragraph); foreach ($funk as $key => $sentence) { if ($sentence != ' ')) { $funk[$key] = "<p>" . $sentence . "</p>\n"; echo $funk[$key]; } } } else { ?> <p><form method="post" action="<?php echo $PHP_SELF?>"> Text:<textarea name="paragraph" rows="10" cols="40"></textarea><br> <input type="submit" name="submit" value="Mangle This"> </form></p> <?php } ?> </body> </html> Thanks in advance, Chris

« previous php.general (#57977) next »