In a HTML form that is processed by PHP:
Would that be output to the browser as:
In other words, do you have to do any sort of special formatting in PHP to make it recognize multiple line breaks?
look at this sample:
$message .= "Hello: " . htmlspecialchars($_POST['hello'], ENT_QUOTES) . "<br>\n";
$message .= "World: " . htmlspecialchars($_POST['world'], ENT_QUOTES) . "<br>\n";
I'm sorry, but I don't really understand how that accomplishes what I'm trying to do. What I want to do is when someone types:
into a HTML form, for the output to be displayed as:
I apologize if I didn't make my first post clear enough
Either output the text within <pre>...</pre> tags, or run it through the nl2br() function:
echo "<pre>" . htmlentities($text) . "</pre>\n";
// . . . or . . .
echo "<p>" . nl2br(htmlentities($text)) . "</p>\n";
Does either method have an advantage over the other?
The nl2br is probably best. However, it outputs <br /> so if you are using HTML DOCTYPE, you probably better use
Ultimately, it comes down to what you are trying to output and how semantically meaningful you want your resulting HTML mark-up to be. You might want to break it up into HTML <p>aragraphs, with:
echo "<p>" . preg_replace('/[\r\n]+/', "</p>\n<p>". htmlentities(trim($text))) . "</p>\n";
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)