This qeustion seems simple but i loss lot of my time playing with it.
My requirement is simple i want a text area that supports line break ie if a user enters(line break) and again types some text.When this value is stored in database and if i want to display that text on some page than it should exactly display with same formatting as entered.
Also the text area should support some special characters like this text mofrém .Here these characters are displayed as boxes.
Using tinymce is an option i guess, but is there any simpler solution? Can these text be manipulated using php?
Any help would be appreciated.
Found a similar question that has been answered:
Preserve Line Breaks From TextArea When Writing To MySQL
Two solutions for this:
eg,
echo nl2br("This\r\nis\n\ra\nstring\r");
// will output
This<br />
is<br />
a<br />
string<br />
<pre></pre>
tags. See: W3C Wiki - HTML/Elements/pre
Edit:
In reply to comment. To store/encode special characters use:
nl2br(htmlspecialchars($text));
Then to decode again special characters:
htmlspecialchars_decode($text);
Reference:
http://php.net/manual/en/function.htmlspecialchars.php http://php.net/manual/en/function.htmlspecialchars-decode.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.