PHP - Nl2br()
i am using the below script that i got from the php manual but it is putting to many <br /> in.
script from php manual Code: [Select] <?php $string_text=file_get_contents("newsletter_files/newsletter.txt"); // load text file in var $new_text=nl2br($string_text); // convert CR & LF in <br> in newvar echo $new_text; // print out HTML formatted text unset($string_text, $new_text); // clear all vars to unload memory ?> this is the source view Code: [Select] <div class="maintext"><center><h1>Newsletter</h1></center><br /> <br /> text here<br /> <br /> text here</div> this is what i put in the text file Quote <center><h1>Newsletter</h1></center> text here text here Similar Tutorials<?php echo nl2br($PostText); ?> In this instance $PostText is: Code: [Select] Welcome to your new forum./n/n This is a default post to show you everything is set up. But it isn't changing the /n to <br>. The database is a varchar(10000) for this required column. I have this code: Code: [Select] <?php $content = preg_replace("/\<\?php.+\?\>/isUe", "highlight_string('$0', true);", $row['content']); $content = nl2br($content); echo $content; ?> What it does is highlight the php, then it converts new lines to <br /> tags, but the problem is that it adds new lines in between the code tags. How can I get it to add new lines everywhere except between the code tags that are created by highlight_string()? Please help refresh my memory... It seems to me that there is some combination with nl2br that is a no-no... I am thinking I need to remove nl2br in this code... <textarea id="comments" name="comments" cols="50" rows="15"><?php if (isset($comments)){echo nl2br(htmlentities($comments, ENT_QUOTES));} ?></textarea> Debbie I am using textarea to get data and entering it into database using addslashes and mysql_real_escape_string $text = $_POST['txttext']; $text = addslashes($text); $text = mysql_real_escape_string($text); Then displaying the data from database on other page using stripslashes and htmlentities $text = stripslashes(htmlentities($rows['text'])); echo nl2br($text); Entire text stretches across the screen and shows in 1 line. Is it because use of addslashes, stripslashes etc ? Hey All, I've tried everything... How can I add nl2br to this, so it fix's quotes and does nl2br. <tr> <td width='200px' valign='top'>Course Overview: </td> <td valign='top'> " . fixQuotes($row['overview']) . "</td> </tr> I have the following code, and for some reason the nl2br() function doesnt work anymore it did until i added the pred_replace part: $topic = $_POST['topic']; $message = $_POST['message']; $board = $_POST['board']; $topic = stripslashes($topic); $message = stripslashes($message); $board = stripslashes($board); $topic = mysql_real_escape_string($topic); $message = mysql_real_escape_string($message); $board = mysql_real_escape_string($board); $message = nl2br($message); $message = preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $message); $message = preg_replace("/\[u\](.*)\[\/u\]/Usi", "<u>\\1</u>", $message); $message = preg_replace("/\[i\](.*)\[\/i\]/Usi", "<i>\\1</i>", $message); $message = preg_replace("/\[center\](.*)\[\/center\]/Usi", "<center>\\1</center>", $message); $message = preg_replace("/\[right\](.*)\[\/right\]/Usi", "<p align=right>\\1</p>", $message); $message = preg_replace("/\[url=http://(.*)\](.*)\[\/url\]/Usi", "<a href=\"\\1\">\\2</a>", $message); $message = preg_replace("/\[img=(.*)\]/Usi", "<img src=\"\\1\">", $message); $message = preg_replace("/\[profile=(.*)\](.*)\[\/profile\]/Usi", "<a href=\"index.php?step=profile&profile=\\1\">\\2</a>", $message); $message = preg_replace("/\[quote](.*)\[\/quote\]/Uis", "<div>Quote:</div><div style=\"border:solid 1px;\">\\1</div>", $message); although im using nl2br, and \r\n in the code below, my results are still displaying; result1,result2,result2 opposed to result1 result2 result3 How can i change to this format? $code = $_GET['postcode']; $message = $_GET['message']; $shortcode = substr($code,0,2); $subject = "subject here"; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; $number_of_results = mysql_num_rows($result); $results_counter = 0; if ($number_of_results != 0) {while ($array = mysql_fetch_array($result)) {$email = $array['email']; $results_counter++; if ($results_counter >= $number_of_results) {$to .= $email;} else {$to .= $email . ',';}}} $headers = 'From: me@me.com' . "\r\n" . 'Reply-To: me@me.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message .= "\r\n". $to ; echo nl2br ($message); mail( "$to", "$subject","$message", "$headers"); echo "<br>" . "Thank you for using our mail form."; ?></body></html> Hi I am trying to use the nl2br function like this while ($row = mysqli_fetch_array($query)) { //May need this later to output pictures // $imageURL = 'upload/'.rawurlencode($row["filename"]); echo " <div class='divTableRow'> <div class='divTableCell'>{$row['User']} ;</div> <div class='divTableCell'>nl2br({$row['CommentText']});</div> </div> \n"; } However the output just looks like the attached picture. When I check in the sql db I can see the line breaks when doing a select * from Table ;
|