I want, that a user can format text (just like in this box) - And should store it in a database.
How can I achieve such a thing?
Save the string containing the HTML code of the text in the database.
Usually a string like this: 'String test format' is saved in the database as '<b>String</b> <i>test</i> format'.
Thanks for every information i got.
Due to you i started looking for wysiwyg ediots. (Like TinyMCE <- but i didnt used that^^)
Im using CKEdior - thanks!
Related
I am creating a laravel web application for a client which allows them to store information into a database.
So i am using a WYSIWYG editor to allow the users to enter data with bullet points, bold text and underlines ect...
Now when i save the description to my database it looks like this.
test test<div><br></div><div><br></div><div><b>egergererh<i>this is a bullet</i><u><i>hello</i>egerg</u>ewg</b>ewg</div><div><br></div><div><ul><li>wegwe</li></ul><ol><li>ewg</li></ol></div>
So when the user previews the page with the description i want it to show with the html marked up. But instead I find a string of html that looks like this on my page.(not the real thing for an example)
test test <div><br/><div></div></div>
How do i retrieve the description from the database and present it to the page as html?
i have tried
htmlspecialchars_decode()
but this doesnt do anything.
try it with:
<?php
$str = 'test test<div><br></div><div><br></div><div><b>egergererh<i>this is a bullet</i><u><i>hello</i>egerg</u>ewg</b>ewg</div><div><br></div><div><ul><li>wegwe</li></ul><ol><li>ewg</li></ol></div>';
echo html_entity_decode($str);
This is maybe a stupid problem to solve but i've looked around and i can't manage to find a viable solution.
I'm making a simple form where:
the user write some text into text-areas
the php must echo back those data into a simple html code to copy it somewhere else
something like this: http://www.w3schools.com/php/showphp.asp?filename=demo_form_validation_complete
but there is a problem even in the demo from w3schools: when i have some text into a *.txt file or another web page/local document and i copy(or cut) and paste it into the form and send to receive the echo it sends back a "null" value from the variable, while it doesn't happen when i type into it.
How can i solve this? Is there a way to send to the variable a copy-pasted text instead of a "null" value?
You may have an apostrophe in the copied text and it's being converted into a curled apostrophe (see: http://www.dwheeler.com/essays/quotes-in-html.html). If you're just echoing it back out to the screen, you could wrap the $_POST['content'] in a htmlentities().
I currently have a MySQL table called _post and i have a column called message (TEXT)
When i insert a row into the table the text looks like this in phpmyadmin
This is Correct How I Want It To Display
How much do you use your computer?
You might be spending to much time.....
But when i echo it out of the database it looks like this
How much do you use your computer? You might be spending to much time.....
Thank You
You should use something like nl2br() function.
Looks like you need to convert \n (newlines) to <br>s.
Since your output is processed as HTML you won't see the newlines that are present in your database. In HTML you need a <br>-tag to display a newline in your browser.
PHP has a function that converts any newline to a <br>-tag for you: nl2br()
You can use the nl2br() function to display your data.
Example:
echo nl2br($mysql_text);
Regards
I have a form where a user types paragraphs into a text area and then it takes them to another page after they submit. How can I pass whatever they typed to the page after they submit? The text area might have linebreaks and if I use a query string to pass the data, it gives me an error. This is my current code to pass the field:
<?php
if(isset($_POST['form']))
{
$title = $_POST['title'];
$body = $_POST['body'];
header("SubmitForm.php?title=$title&body=$body");
?>
<html>
...html form...
It doesn't work when the text area has line breaks in it.
I would suggest installing a wysiwyg editor to make this easier for you, but i assume that would add some time for the learning curve.
The simplest tips I can give you is to set a CSS attribute for your textarea: white-space:pre so that when it gets submitted, all line breaks get sent as well.
On your server side, you would need to use the nl2br() function, so that when it gets saved on your DB or wherever you store them, all line breaks are converted to HTML breaks.
For your additional reference, I had a similar question like this last year.
You really shouldn't be putting anything that long in a query string in the first place. Look into using sessions to store data across pages instead.
(This is assuming I understood the question right)
urlencode the data in order to pass it via query string.
so I need the user to write a review about an article or book and send it to a DB via PHP but with some basic HTML formatting.. I mean, I have a form , when the user writes the review, the data is sent but without any kind of formatting, If the user want to write in a new line, the text is sent like plain text, I need to get also those new line breaks and simple stuff.
I know how to use PHP and DB connection, I just need to know how to get those new line breakes and stuff..
Use nl2br
Just before printing on the screen data from DB. It replaces \n (new line) as <br>
I recommend storing the data as plaintext, and adding the formatting on the way out. This way if you want to change the way it is formatted then you don't have to update every row in the database.
you can use nl2br() if you just need to newlines to be formatted, and a search-and-replace for anything else.
Have you considered using an existing 'plain text to markup' solution, like Markdown?
It (and others like it) allow your users to write plaintext reviews that will be sensibly formatted. (like stackoverflow uses!)
The PHP function nl2br() basically takes every new line your user enters via the form and converts the new line code to a <br> tag.
An example of using this would be:
$text = nl2br("This is text \nThis is a new line of text");
This would create the following code in your database:
This is text<br>This is a new line of text
When the user hits enter in the form textarea, PHP will pick this up as \n.