Forum Moderators: coopster
I make a user registration form. I saved this data in table of mysql. Here is one field description in table this is of Text type. It stores details about company.
Now problem is that user enter data in description field with formatting means using newline charaters [line feed, tab]
but when i retrive data from table it shows Description field data in a single line with no formatting.
Please tell how to do this.
It is just like we are posting messages in forum. It saves with formatting like tabes, enters etc. and shows thread with same formatting.
Thanx,
The first one should be always use before inserting data in database. It replace <br> by a return+new_line. And it uses htmlentities to make it safe
function var_html_encode ($varia) {
$varia=rtrim($varia); $varia=ltrim($varia);
$varia=str_replace("<br>","\r\n",$varia);
$varia=htmlentities($varia,ENT_QUOTES,"utf-8");
return $varia; }
The second function below should be used when fetching data from database. As you can see, it uses html_entity_decode (inverse of htmlentities) and replace the return+new_line by a <br>.
function var_html_decode($varia) {
$varia=rtrim($varia);
$varia=ltrim($varia);
$varia=html_entity_decode($varia,ENT_QUOTES);
$varia=str_replace("\r\n","<br>",$varia);
return $varia;}
This function is slightly similar than the one above, the only difference is that it removes all HTML element, excepted <br>.
function var_html_tagdecode($varia) {
$varia=rtrim($varia);
$varia=ltrim($varia);
$varia=html_entity_decode($varia,ENT_QUOTES);
$varia=str_replace("\r\n","<br>",$varia);
$varia=strip_tags($varia, "<br>");
return $varia;}