FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Store data format as user entry





abhiz
i having trying to learn using the databases for my website but had problem.
i n my guest book when I retrieved the data from the databases I get it in all same paragraph. I could not get it it different para. Can any one let me know how to store data as user enter with proper NEW LINE SPACE etc..
kv
if you are displaying it in the browser, you will need to replace new line characters (\n) with <br> before storing into the database. Otherwise, even if you store it with new line and retrieve it properly, browser won't display it in separate lines.
abhiz
Yea just I want to know how to HTML encode and store it in the database
SamiTheBerber
abhiz wrote:
Yea just I want to know how to HTML encode and store it in the database

One method is
Code:
$text=str_replace("\n","<br />",$text);
where $text is message from your guestbook.
abhiz
Can you specifically tell me how to do it
M really in need
U got my problem
M just unable to do that replace '/n' with '<br>' and other character.
waiting for your early response
sonam
For example your textarea have name "text".

Code:
$text = $_POST['text']); // post your data

// Convert all applicable characters to HTML entities
$text= htmlentities($text);

// check for enters and replace it in <br />
if (strstr($text, "\n") || strstr($text, "\r")) { 
       $text = preg_replace('[\r\n]', '<br />', $text);
}


You can try also nl2br() function, but in my case it is not working on my localhost.

Sonam
abhiz
sonam wrote:
For example your textarea have name "text".

Code:
$text = $_POST['text']); // post your data

// Convert all applicable characters to HTML entities
$text= htmlentities($text);

// check for enters and replace it in <br />
if (strstr($text, "\n") || strstr($text, "\r")) { 
       $text = preg_replace('[\r\n]', '<br />', $text);
}


You can try also nl2br() function, but in my case it is not working on my localhost.

Sonam


thankz sonam m trying
Related topics
How To : Improve Your PHP Programming
Hard disk having problems
mysql_real_escape_string question
Do you use XML ?
Help with User Form Validation
A good place to learn Java
Java - Storing data in a file
Increase XP NTFS Performance
Lock this thread - RSS feeds for 20 Frihs$
New organic material for transferring data
DVD Burner
8 Ghostly registry deletes every time I boot my Portable
Linux distribution switch
%temp%
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.