I have inserted my code in mysql database using text area.
What I have save appears is like this in mysql
This is Line 1
test
This lis Line 3
Now, my problem is to display the saved "file" to my browser which I am expecting to appear like this.
This is Line 1
test
This lis Line 3
Has anyone have some situation like this?
Use htmlentities on your output display. You can save html or any code as is in mysql with no special attention. You will need to escape it though so user based input isn't malicious.
http://www.php.net/manual/en/function.htmlentities.php
htmlentities("URL", ENT_QUOTES, 'UTF-8');
If you run this in php you will display the whole html tag. Likewise, you can spew out results from a mysql query, wrapping the relevant content in htmlentities to achieve what you're looking to do.
Related
Using p session.inspect outputs a single line. I want to add a html-container in my application view, always showing what's inside the session. But this should be properly formatted with indentations and breaks. Is there a way to achieve this?
In PHP, e. g., you can wrap the output of $_SESSION in a <pre>-tag and it will automatically be properly formatted.
I have a form with a text area as one of the input fields. I want to store the user entered data. In the process I need to store the \n (enter key). But here the problem is in the DataBase (MySql) data is stored, but \n is not stored; i.e. data store as:
.
When I display the same data in the browser it shows in single line.
I need to split the data with \n and it should look like:
When I display the same data in the browser it shows in single line.
Yes, it would - because a newline in HTML doesn't get rendered as a newline. If you look at the raw HTML, I suspect you'll still see the line breaks... it's just that's not how it's rendered.
In order to represent line breaks in HTML, you need to use <br /> between lines, or something similar - or display it with a <pre> tag.
Basically, you need to format your raw text as HTML, however you decide to do that. If you're just dumping the HTML straight into your page, you may well find you already have issues if the text contains HTML tags - they should be escaped.
If you are seeing \n being stored in database, then you can write logic to include
<br/> tag while printing database values on your jsp.
Not sure if I am asking this correctly. But I am using a Jquery HTML Editor cleditor so that the users can load html text. When I insert this into my db(mysql) and want to display the outcome it takes out any html characters it had like: <p>, <span>, and so on. So when I go view it, it shows like this:
class=\"noticia_texto\">jlasdfklsfklaf
which obviously it's not readable. Help please? Should I be using anything at the time of inserting or displaying or both? Also my datatype is set to Blob.
MySQL does NOT strip html tags. If they're being removed upon insertion (or retrieval), then it's something in your code doing it, not MySQL.
Given that the quotes in your snippet are escaped, you've almost certainly got magic_quotes enabled, and/or a home-brew SQL escaping function run amok.
I have what is a simple problem that hopefully has a simple solution:
I have a site written in PHP and HTML, using a Linux server with MySQL.
It has a form where users fill in some personal info, including a textarea in which
they are meant to copy and paste a test CV.
I have also set up a back end for my client where she can query the database to see who
registered and retrieve their info.
My problem is that when I query and echo the content of the table row that contains the
CV (alot of text), the line breaks are all gone - everything is printed in one line.
Does someone know if I can solve this by using the right kind of collation/character encoding
for that specific row that contains the users's cvs? I am hoping that such collation exists that saves and maintains line breaks.
Collation has nothing to do with it - collations and charsets won't touch your newlines at all. If you want to see it, look at the page source of the echo'd text.
HTML, however, treats line breaks like all other whitespace under normal circumstances, so they won't be visible when you echo them to a browser. You shouldn't be outputting plain text as HTML anyway, because they're not the same. You must convert the plain text to HTML first; a simple method is to call htmlspecialchars() and nl2br() on the text (in that order, otherwise htmlspecialchars will eat your newly-created br tags and turn them into <br/>. Failing to do so will not only create undesired output, it can also be a major security risk (XSS).
Use nl2br($text) to add HTML line breaks.
I don't think collation is related to this. Break lines from the textarea come in the form of the \n or \r characters. If you are not doing anything "weird" those break lines should be stored into the DB.
I think your problem is when you echo the content of the table, since the browser doesn't display the \n and \r as new lines, you have to either substitute them for <br/> element or wrap each paragraph in a <p></p>
You can use nl2br() for that.
or how about wrapping the text in a <pre> </pre>
see: http://www.w3schools.com/tags/tag_pre.asp
I have a text area in html and a form to store the information in the database. When I click on submit, it supposed to take this text and save it in the database. For example:
"This is a text and this is a list:
1. number 1
2. number 2"
However, when I load the information from the database it looks like:
"This is a text and this is a list: 1. number 1 2. number 2"
How do I keep the layout of the textarea not changed (keep the spaces, lists, etc) without the need for the user to enter any tags.
It's being stored just fine in the database. You're outputting what was entered as plain text as HTML, and HTML ignores line breaks. You need to convert your \n characters to <br /> tags. PHP has a nl2br() function for this.
You could have them enter the data in a WSYWIG and do the work on your side to make sure it's always formatted properly - client-side users still won't have to see any tags, especially if you limit their editing options...
tinyMCE, nicEdit are two good editors