Re: Simple (??) control structure problem
| From: | James, Yz | Date: | Sun, 15 Jul 2001 20:01:19 +0000 |
| Subject: | Re: Simple (??) control structure problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-57978@lists.php.net to get a copy of this message | ||
Hi Christopher,
Why not use nl2br() and trim() ?
$string = trim($string); // Clear any unwanted white space (trailing and
leading);
$string = nl2br($string); // Add line breaks where necessary
echo "$string"; // Voila
James
"Christopher Kaminski" <chronoszero@hotmail.com> wrote in message
news:20010715193846.95863.qmail@pb1.pair.com...
> 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
>
>