How do I insert paragraph into database, without losing line feeds?
As you know, clients often like to be able to enter their own content on their websites.
I create a simple user interface where the client can enter fields such as Name, Address, Phone, etc.
I then insert each into the appropriate fields of my SQL database.
My problem is when I try to insert a "whole paragraph", ( if they want to update the "News",etc on their site) that I would output into a div.
When the user clicks "Submit", the data gets inserted into a field in my SQL database. PROBLEM: when I output it onto my page (say, into a div), it is one continuous string of data, meaning the line feeds are ignored.
Is there a way that I can correct this issue? Or steer me in a direction? I would like to know if there is a trick to this? I cannot be the first one running into this issue.
Any help would be appreciated! Thank you very much in advance.
What do you mean by line feeds? I don't understand what is being lost, or rather what your desired result is. A paragraph seems like it should be a single string.
Also, there is paragraph tag in HTML. Just putting it out there.
I am pretty sure that the problem is that I save my $paragraph as a VARCHAR(400).
So when I display it, it just spits it out (and ignores the line breaks).
Maybe I have to have multiple entries for "paragraph1", paragraph2"...... and then do something like:
BUT.... I was hoping there was some "canned" php code available, or a strategy that someone might have.
I hate to have to use a massive CMS application, when many sites are small and I often code my own sites using (html/CSS).
Any help would be greatly appreciated!.
Last edited by Eggweezer; 12-04-2012 at 02:36 PM..
Whitespace is ignored in HTML (as well as PHP, although a linefeed in a string is a char, so it will retain those).
Wrap the content into nl2br() function prior to outputting (don't do it before inserting).
That will insert a <br/> before the \n, so the HTML is given a breaking space to force the newlines.
The preceding whitespace isn't necessary in your original output. To give it the "indented" look, modify the .paragraph CSS code and add a text-ident: {x}px with whatever your preferred indent choice is (1em may be a good option).
is there an easy way to put a indents (tabs... \t - I guess) at the beginning of each paragraph,
and a break (line feed) at the end of each (to separate them?
Last edited by Eggweezer; 12-04-2012 at 03:34 PM..
Don't. Use your CSS to add text indentation and margin's to control the space between the divs. Whitespace (such as tabs) are ignored by HTML unless they are contained in a preformatted text block.
Define a paragraph? Your not referring to the <br/> that breaks the string are you? If so, then you'll need to instead replace the \n with the <p> tags instead of using nl2br.
Also, you'll need to fix'em up the HTML errors as well. Rendering can be easily broken by bad HTML. Hit up the validator.w3.org to check it; I see these: </br>"."</br> as well as these: <B>Name:</B> which are not valid markup tags.
See how the first paragraph indents, but the second and third do not?
That is what I was hoping to be able to correct.
Also, I do understand what you mean about the validating and will fix my errors. Not an expert yet, so will have to figure out why it gives me so many errors on my <b> and </br> tags.
</br> isn't a valid tag. There is no opening <br> tag for it, so with an XHTML doctype you would use a single sided tag which is <br/>. <B> doesn't exist in XHTML standards, but you can use <b>.
I won't follow links from work. If you mean that your string retrieved from storage should be broken into paragraphs on linefeeds, use this instead: