• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[PHP] How to Retain <BR>?

madmatt

Bow Down to the King
Political User
#1
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.
 

albybum

Penguin Rancher
#2
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?
 

madmatt

Bow Down to the King
Political User
#3
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).
 

bush dogg

OSNN Senior Addict
Political User
#4
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.
 

SPeedY_B

I may actually be insane.
#6
<br /> = XHTML
<br> = HTML

They should both work, unless your browser decides to throw a fit, though technically they shouldn't be used together.
 
#7
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.
 

madmatt

Bow Down to the King
Political User
#8
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?
 

SPeedY_B

I may actually be insane.
#9
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.
 

albybum

Penguin Rancher
#11
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.
 

madmatt

Bow Down to the King
Political User
#13
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.
 

madmatt

Bow Down to the King
Political User
#14
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies