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" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]