What I want is when user give line break in description box ie: textarea
in HTML
then all the data is stored securely in SQL database, but if users give links then links becomes also text but when user give enter or line break in description textbox then it saves in the database and while retrieving it from the database the line break will show again.
<textarea name"description" id="description" rows="4" cols="50">
//In The text area the user enter the text. Here I want if user gives html links then links becomes text and if user give line break then line break store in the database and I can get back as it is how user submitted the form. Also I want to store data securely for avoiding sql injection but dont have the exact idea how to do it.
</textarea>
$text = $_POST['description'];
$text = htmlentities($text); // Here I want to remove html entities for avoiding sql injection
$text = mynl2br($text);
// Now Fire Insert Query All the data save but while retrieving the data I am not able to get line break and turning links to the text.
function mynl2br($text) {
return strtr($text, array("\r\n" => '<br />', "\r" => '<br />', "\n" => '<br />'));
}
This is what I am doing it but the links is still the links and when I retrieve the text is showing without line break. All the text in one line or one paragraph.
Kindly suggest what I am doing wrong in the above code. And how can I avoid sql injection and can store and retrieve data securely.