<br> when user presses Enter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

<br> when user presses Enter

Post by anand »

Hi, I am making a forum where I want to have a system by which, while composing a message, whenever a user presses the enter key, then a new line ( \n or <br>) should come up. Also, same goes for bold and italics.

( P.S. Just like this forum.)

Please help.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: <br> when user presses Enter

Post by jayshields »

I don't know what you mean.

My suggestions are either <textarea>, BBCode, or TinyMCE, or a combination of those.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: <br> when user presses Enter

Post by Eric! »

The actual text area is done in HTML with a textarea and a form. The data is then passed on to a php script which needs to filter it for possible XSS, SQLi or email (if going to the mail() function) attacks. Please educate your self on how to filter for those things before making your site available to the public.

Here is a form that passes the data via $_POST to message.php

Code: Select all

<html>
<head>
<title>Contact Us</title>
</head>
<body>
<div align="center">
  <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="453">
  <tr>
    <td valign="top" height="100%" style="border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:none; border-bottom-width:medium" width="453">
    <form name="Message" action="message.php" method="POST" >
      <p><strong>Enter your message in the space provided below:</strong></p>
      <dl>
        <dd>
        <textarea name="Comments" rows="5" cols="42" style="text-align: left; line-height: 100%" maxlength="1000"></textarea></dd>
        <dd>&nbsp;</dd>
      </dl>
      <p align="center">
      <input type=SUBMIT value="Send Message">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="RESET"></p>
    </form></td>
  </tr>
</table></body>
</html>
iBroughtCookies
Forum Newbie
Posts: 10
Joined: Wed Jun 24, 2009 12:09 pm

Re: <br> when user presses Enter

Post by iBroughtCookies »

I would send the data to mysql, then when the data is pulled FROM mysql(I.E. when a user views a page), then you would run this code:
So let's say that you already retrieved the post data, and it's stored in the variable $text:

Code: Select all

 
<?php
$text = str_replace('
', '<br />', $text);
$text = preg_replace('/[b](.*?)[\/b]', '<b>$1<\/b>', $text);
$text = preg_replace('/[i](.*?)[\/i]', '<i>$1<\/i>', $text);
?>
 
Now $text WOULD contain formatted code;
HOWEVER, I can pretty much tell you for a fact that that preg_replace is wrong because I don't know how to use regular expressions :(
Still learning!
Last edited by Benjamin on Wed Jun 24, 2009 12:48 pm, edited 1 time in total.
Reason: Changed code type from text to php.
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: <br> when user presses Enter

Post by anand »

ok, let me explain.

I have a textarea where users can write reviews. Now to make that attractive, users might want to add designs, .like bold, italics, list etc.

now, how to give that features to users?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: <br> when user presses Enter

Post by califdon »

anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: <br> when user presses Enter

Post by anand »

anyways, leave it

i am using wysiwyg editors.

thanks for help
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: <br> when user presses Enter

Post by anand »

This one is even better
Post Reply