Re: Htmlentities and Newlines?
| From: | Christopher J. Crane | Date: | Sat, 28 Sep 2002 19:26:06 +0000 |
| Subject: | Re: Htmlentities and Newlines? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-117970@lists.php.net to get a copy of this message | ||
$Something = str_replace("\n", "<br>", $Something);
This is old but still works well.
"Andre Dubuc" <aajdubuc@webhart.net> wrote in message
news:200209281800.g8SI0bN08316@filtermail.webhart.net...
> Perhaps I don't understand the use of 'htmlentities' too well, but I would
> like newlines to be retained/inserted into a db, and then if displayed, to
> produce a new line from a textarea. However, I want the possibility of
> dangerous html excluded (hence the use of 'htmlentities').
>
> Is there some way of excluding '\n \r ' and other newline indicators from
> 'htmlentities()'? Perhaps a combination of preg_match and something else?
I'm
> a bit brained-fried struggling with other errant parts of this code since
6
> am.
>
> Any ideas how I could proceed?
>
>
>
> The code far:
>
>
> <?php
> . . .
> /* Verification script. Adds sponsor's name, city, prov, country and
current
> date at end of 'request' string */
> . . .
>
> $request = $_POST['request'];
> $request = ucfirst($request);
> $html = htmlentities($request);
> ^^^
> /* $html defuses all newlines . . . sigh */
>
>
> $title = $_POST['title'];
> $title = ucfirst($title);
> $title = htmlentities($title);
>
>
> $date = date('Y-m-d');
> $preview =
>
> "{$_SESSION['title']}<br><br><br>$html<br><br><br>{$_SESSION['sfname']}
> {$_SESSION['ssname']}<br>{$_SESSION['scity']},
> {$_SESSION['rprov']}
> {$_SESSION['scountry']}<br>$date";;
>
>
> print "<h2>Preview of Request from
>
> {$_SESSION['sfname']}{$_SESSION['ssname']}</h2><br><br>";
> . . .
> ?>
>
> Any ideas or advice will be most gratefully accepted.
> Tia,
> Andre