[PHP] How to Retain <BR>?

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
Okay, I feel really dumb for not knowing this but I can't figure out what I am doing wrong.

When I add new content to my blog I am using the following MySQL statement:

Code:
$addArticle		= nl2br(trim(addslashes($_POST['blogformArticle'])));

When I update content on my blog I am using the following statement:

Code:
$updateArticle	= nl2br(trim(addslashes($_POST['blogformArticle'])));

When I display the content I use the following statement:

Code:
$viewArticle	= stripslashes($viewRow["article"]);

However, it won't display it with the <br />'s in place. This is the HTML code:

Code:
Microsoft said on Friday that it is recalling an update to its Small Business Server product because of a glitch found late in the manufacturing process. <br />
<br />
The software maker said it found a problem with Windows Small Business Server 2003 R2 after the product was released to computer makers but before it was made broadly available. Small Business Server is a product that combines the Windows Server operating system with the Microsoft Exchange e-mail server and other software. The R2 release is an update to the version that was finished in 2003. <br />
<br />
"Recently, and during a regular audit as part of our software production process, Microsoft became aware of an issue with the final...software containing nonfinal versions of a few core components," Microsoft said in a statement provided to CNET News.com. "Since Microsoft has only just released SBS 2003 R2 to our manufacturing partners (OEMs, system builders and distributors), and it is not yet generally available to customers, the scope of this concern for partners and customers is very limited." <br />
<br />
Microsoft said it was recalling and would reissue the software, and general availability of the product would see a "minor delay." <br />
<br />
"Our customers and partners are our first priority, and while a short delay in availability of SBS 2003 R2 is unfortunate, delivering the highest-quality Small Business Server product to our customers and partners is the right thing to do," Microsoft said. <br />
<br />
One analyst said the fact that a glitch can show up so late in Microsoft's manufacturing process shows the challenges the software maker faces as its software becomes ever more complex. That challenge is heightened by the fact that the company no longer relies on burning all of its products to CDs; it doesn't have the luxury of taking that time to find bugs. <br />
<br />
"This isn't really a stellar advertisement for Microsoft's plan to roll out more and more complex software through automatic update," Directions on Microsoft analyst Rob Helm said. <br />
<br />
While this glitch affected just a few people, Helm said, a problem with something going out over Automatic Update could potentially affect millions of people. Microsoft said earlier this week that it would use the autoupdating utility to deliver Internet Explorer 7 for Windows XP.<br>

None of the blank lines appear and I don't know what I am doing wrong. Technically, there should be a blank line in between each paragraph, the <BR /> is there after all.

Any help is appreciated. Thank you.
 
I do not see anything in the above-posted code that would strip off <br />.

nl2br()
trim()
addslashes()

I tested these to make sure, and they do not affect that tag.

Somewhere before you send the data to the database, something may be parsing out html. Is this a specific blogging package or your own code?
 
I wrote the code from sratch. It shows in the MySQL db/table correctly. However, when it is displayed as HTML it won't put the line break in (although the second <BR> is there).
 
I don’t recall using <br /> at the end to skip a line.

I use <br> to skip a line. I would try a line with just <br> and see if that’s what you want.
 
nl2br adds the breaks in as <br /> automatically (XHTML compliant).
 
<br /> = XHTML
<br> = HTML

They should both work, unless your browser decides to throw a fit, though technically they shouldn't be used together.
 
personally I would not nl2br the string when you are putting it into the database. Then when you edit it you are doing to have a load of <br/> tags in your textarea. It would be better to maintain the newline (\n) characters and nl2br the text before you output it for the normal rendering.
 
I am using striptags (except <b><u><i><a>) when I bring it back into the textarea. How would I automatically add in the \n when I send it from the textarea to the MySQL db/table?
 
That should be done automatically. I don't touch the line-breaks sent from my PHP to the SQL until it's read back and displayed on the page.
 
nl2br should not be stripping out any html, much less line breaks. It's only purpose is to find and replace \n with <br />.

I tested this to make sure.

Check to make sure <br /> is excluded from striptags and you aren't stripping out html tags or < > symbols before you print your database or rss values.

That's about the only thing I can imagine would cause the problem.

[edit] View Source on your rss feeds show line breaks written as &lt;br /&gt; not <br />

If they come back into the html that way, they might be interpreted as literals and not html tags.
 
The blog pulls the data right from the MySQL table. The RSS feed pulls in the data from the MySQL table then converts it to XML.
 
Never mind. I found a work around. I think it's a problem with IE and the way it handles <br> on an empty line.

Code:
$article = str_replace("<br />", "&nbsp;<br>", $article);

Now the line isn't technically empty and contains a space. It works fine now. Thank you to everyone who helped.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back