View Full Version : Enter Ignored !!!
ASHORY
04-14-2007, 02:01 AM
HI ,
Now i have a small problem in there
iam making something like a forum , you can call it tiny forum.
anyway , heres the problem
when i make a new post and write the data as follows :
blabla
1234
5678
so when i save and view this message it shows as follows:
blabla12345678
means it Ignores the ENTER so how can i fix that out .
thanx
check out nl2br() (http://www.php.net/nl2br)
New line characters (\n) are carraige returns which are new lines within files, and within textareas, but to show new lines in html, you need to convert the newlines to <br>, hence the very original function name, nl2br()
ASHORY
04-14-2007, 03:34 AM
Thank You <H1> ;)
ASHORY
04-23-2007, 02:49 PM
but , i faced a problem .
it is when i edit and save each time it enter a new <br> plus the old one
so if the first view was like that :
1
2
3
it becomes like that
1
2
3
4
and so on ....
so thats not what i needed . so what can i do .
is there anther method or what
johnz
04-23-2007, 02:57 PM
If you are using nl2br(), there is no need to manually type in the <br /> tag.
ASHORY
04-23-2007, 03:16 PM
i dont type it manually but i use nl2br , and it add a <br /> every time i edit the message
so it will be like i showed
Can you post your script? The issue seems to be in the way you are modifing the information.
ASHORY
04-24-2007, 02:15 PM
its just a form posting then , adding to a data base
index.php
<form action=save.php method=post>
<textarea name=message></textarea>
</form>
save.php
$Message=nl2br($_POST['message']);
$Query=mysql_query("UPDATE messages SET Msg='".$Message."'");
thats the code , similar to the one i did . coz the other has more than what i need . thats all what we need for this problem
But that should work. What we really need to see is how you are editing the information. Do you pull it out of the database first, display it in a textarea, and then save it again?
Try not applying nl2br() on the data your are editing, only on what you are adding for the first time.
ASHORY
04-24-2007, 03:34 PM
but this is the user edited the message with anther 2 or 3 lines it wont be with <BR> . so the same problem came again
eTwerp
04-25-2007, 08:55 AM
When you pull the message out of the database to edit do you use strip_tags so the message is without any br tags and when you update the message you can apply nl2br again.
Something like that should work.
But as Paul said, seeing how you edit the information would be helpful.
ASHORY
04-25-2007, 03:27 PM
Great . this worked pretty well . thanks eTwerp and thanks all
eTwerp
04-26-2007, 02:55 AM
Glad it's working :)
scoutt
04-26-2007, 08:14 AM
or you can str_replace() the <br> with \r\n so it reads like they posted it in the textarea
ASHORY
04-29-2007, 01:14 PM
yeah , but the strip_tags removed it so it worked for me better than the str_replace
scoutt
04-29-2007, 01:33 PM
sorry but strip_tags does not remove \r\n from the posted texarea.
let me explain a little more.
if you allow the user to enter line breaks in the textarea and then you use nl2br when it goes into the database and then when you grab that information out and use strip_tags it creates one line, not showing the exact message the user entered in the textarea.
ASHORY
04-29-2007, 01:39 PM
no it worked with me fine showing the exact message .
but users are not allowed to enter a line breaks ..
he just use ENTER to break the line ...
scoutt
04-29-2007, 01:43 PM
but users are not allowed to enter a line breaks ..
if you use this
$Message=nl2br($_POST['message']);
you do allow them to enter line breaks.
so, when they post, then you create a chance of it add this
"this is a comment with<br>extra line";
In the database. using strip_tags all it will do it take away that <br> and it still still be one line even though the user had a line break. I am saying it is best to use str_replace() on those as it will allow you to add the <br> back and take it away with no harm to the original message. stip_tags will limit you in the long run.
Right thing would not put the html tags in the database in the first place if not using a wysiwyg editor or lookalikes to format the input.
Simply entering them into database with mysql_real_escape_string() then when outputting use
// Order of replacement
$str = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order = array("\r\n", "\n", "\r");
$replace = '<br />';
// Processes \r\n's first so they aren't converted twice.
$newstr = str_replace($order, $replace, $str);
Which takes into consideration windows, linux and mac newline which all are different.
ASHORY
04-30-2007, 05:59 PM
ya , Got it !! , thanks guys . i didnt get it at first ...
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.