![]() |
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. |
Let me see if I can better explain my situation.
Here is an example of what I mean (at this link). http://sample.cnjwebsolutions.com/user/add.php 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: if($paragraph1<>"")echo $paragraph1."</br">; if($paragraph2<>"")echo $paragraph2."</br">; if($paragraph3<>"")echo $paragraph3."</br">; 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!. |
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. PHP Code:
Code:
Text with <br /> |
I kind of understand what you are saying, but am not quite sure where to implement it. I am attaching my code, if you would be so gracious to show me.
PHP Code:
|
Replace this:
PHP Code:
PHP Code:
text-ident: {x}px with whatever your preferred indent choice is (1em may be a good option). |
Fou-lu...You just made my day! (year maybe!)
Thank you so much. Works perfectly! Thanks all. |
Last thing, and am sorry to bother you, BUT.....
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? |
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.
|
Quote:
Code:
<p class="paragraph">Code:
p.paragraph{ |
Still not quite right.
It only indents the first paragraph, unless I missed something. http://sample.cnjwebsolutions.com/index.php PHP Code:
|
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. |
you can use wysiwyg-editors like tinymce or ckeditor. They insert paragraph tags automatically and you are also able to edit plain html in editors
|
My (definition... and I probably didn't describe it right...) of paragraph, can be seen on my current page: http://sample.cnjwebsolutions.com/index.php
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. Thank you. |
</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: PHP Code:
|
| All times are GMT +1. The time now is 12:09 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.