Jump to content

Converting textarea spaces to breaks


Eevee-chan

Recommended Posts

Hi, my friend and I are coding a PM system, and we're using (of course) a textarea for message input. When we tested it we discovered that whenever we spaced a line down in the text area, it appears as an "rn". We tried

 

$message = wordwrap($message, 1000, "<br />\n");

 

But that didn't work - is there a way we can do this?

Link to comment
https://forums.phpfreaks.com/topic/37065-converting-textarea-spaces-to-breaks/
Share on other sites

Sure. WritePm.php:

 

<?php
$usepms="Yes";
$maxpms="50";
?>

<?PHP
if (isset($_SESSION['user']))
  {
    $getpms="SELECT COUNT(*) from b_pms where receiver='$getuser3[userID]'";
      $getpms2=mysql_query($getpms) or die("Could not get PM!");
      $getpms3=mysql_result($getpms2,0);

$percent = ($getpms3/50)*100;
$bar = ($getpms3/50)*100;
$bar2 = 100-$bar;

    $user=$_SESSION['user'];
    $getuser="SELECT * from trainers where Username='$user'";
    $getuser2=mysql_query($getuser) or die("Could not get user info");
    $getuser3=mysql_fetch_array($getuser2);
echo "
<h1>$user's vMail Inbox</h1>
Welcome to your vMail Inbox, <strong>$user</strong>! What would you like to do?
<center><a href='index.php?act=WritePm'><button>Compose</button></a><a href='index.php?act=deleteread'><button>Delete Read Mail</button></a></center>
";
    if(isset($_POST['submit']))
    {
       $name=$_POST['name'];
       $suser="SELECT * from trainers where Username='$name'";
       $suser2=mysql_query($suser) or die("Could not get user");
       $suser3=mysql_fetch_array($suser2);
              

if(strlen($_POST['name']) == '')
       {
         print "There is no trainer with that specified username.";
       }
       else if(strlen($_POST['subject'])<2)
       {
         print "You must enter a vMail subject.";
       }
       
       else if(strlen($_POST['message'])<1)
       {
         print "You must enter a message.";
       }
       else
       {
          $subject=$_POST['subject'];
          $message=$_POST['message'];
	  $message = wordwrap($message, 1000, "<br />\n");
          $date=date("U");
          $vartime=date("D M d, Y H:i:s");
          $sendmessage="INSERT into b_pms (sender, receiver, subject, message, therealtime)
          values('$getuser3[userID]', '$suser3[userID]', '$subject', '$message', '$date')";
          mysql_query($sendmessage) or die("Could not send message");
          print "<center>vMail message delivery complete!<p><a href='index.php?act=vMail'><button>Go Back</button></a>";
       }


    }
    else
    {
       if($usepms=="Yes")
       {
         $countpm="SELECT COUNT(*) AS pmcount from b_pms where receiver='$getuser3[userID]'";
         $countpm2=mysql_query($countpm) or die("Could not count pms");
         $pmcount=mysql_result($countpm2,0);
         if ($pmcount>$maxpms)
         {
            print "The recipient you are trying to send mail to has reached their mailbox quota.";
         }
         else
         {
            print "<form action='index.php?act=WritePm' method='post'>";
            if(isset($_GET[name]))
            {
              $name=$_GET['name'];
              print "<input type='hidden' name='name' value='$name'>";
            }
            else
            {
              print "<strong>Recipient:</strong><br />";
              print "<input type='text' name='name' size='20' maxlength='20'><br>";
            }
            print "<strong>Subject:</strong><br />";
            print "<input name='subject' type='text' size='25' maxlength='25'><br>";


		print "<strong>vMail Message:</strong><br /><textarea rows='15' name='message' cols='50'></textarea><br>";
		print "<button type='submit' name='submit'><img src='images/send.gif' /></button>";
		print "</form>";

    
         }
       }
       else
       {
         print "A staff member has disabled the requested user's mailbox.";
       }

    }
  }
if(!isset($_SESSION['user']))
  {
    print "You must be logged in to write vMail.";

  }
?>

 

And readpm.php:

 

<?php
$usepms="Yes";

?>


<?PHP

$$getpm3[message] = wordwrap($getpm3[message], 1000, "<br />\n");

if (isset($_SESSION['user']))
  {
      $getpms="SELECT COUNT(*) from b_pms where receiver='$getuser3[userID]'";
      $getpms2=mysql_query($getpms) or die("Could not get PM!");
      $getpms3=mysql_result($getpms2,0);

$percent = ($getpms3/50)*100;
$bar = ($getpms3/50)*100;
$bar2 = 100-$bar;

    $user=$_SESSION['user'];
    $getuser="SELECT * from trainers where Username='$user'";
    $getuser2=mysql_query($getuser) or die("Could not get user info");
    $getuser3=mysql_fetch_array($getuser2);
    print "<center>";
        print "<table class='maintable' width='100%'>";
    print "<tr><td style='border:1px solid black' colspan='5' bgcolor='green'><center><font face='verdana' size='1' color='green'><b>$user's PokeMail-Box</center></td></tr>";
    print "<tr class='forumrow'><td colspan='5'>";
    print "<table width='100%' cellspacing='2' cellpadding='3' colspan='4'><tr><td valign='top'><font face='verdana' size='1'>Welcome To Your PokeMail-Box <b>$user</b>, What Would You Like To Do?<br><A href='index.php?mode=WritePm'>Compose A PokeMail Message</a> | <A href='index.php?mode=deleteread'>Delete Old PokeMail</a></td></tr></table></center></tr><tr><td style='border:1px solid black' colspan='4' bgcolor='$font'><font face='verdana' size='1' color='green'><b><center>PokeMail Message</td></tr><table cellspacing='1' cellpadding='2' bgcolor='$font' style='border:1px solid black' width='99%'>";
    if($usepms=="Yes")
    {
      $ID=$_GET['ID'];
      $getpm="SELECT * from b_pms as a, trainers as b where a.pmID='$ID' and a.receiver='$getuser3[userID]' and b.userID=a.sender";
      $getpm2=mysql_query($getpm) or die("Could not get pm");
      $getpm3=mysql_fetch_array($getpm2);



      print "<tr><td style='border:1px solid black' bgcolor='green' width='140'><font face='verdana' size='1'><b><center>$getpm3[username]</a></b>";    


print "</td>";
      $getpm3[message]=strip_tags($getpm3[message]);
      $getpm3[message]=htmlspecialchars($getpm3[message]);
      $getpm3[message]=nl2br($getpm3[message]);
      $getpm3[message]=BBCode($getpm3[message]);
  

print "<td valign='top' style='border:1px solid black' bgcolor='green'>";
     print "<font face='verdana' size='1'><br><br>$getpm3[message]<br><br></td></tr></table><p align='right'><font face='verdana' size='1'><a href='index.php?mode=ReplyPm&ID=$ID'>Reply To PokeMail</a><br><br><a href='index.php?mode=Inbox'>Return To PokeMail-Box</a>";
      $updatenote="Update b_pms set hasread='1' where pmID='$ID' and receiver='$getuser3[userID]'";
      mysql_query($updatenote) or die(mysql_error());
    }
    else
    {
      print "The Administrator has turned off PMs.";
    }
  }
else
  {
    print "<center>Sorry You Must be Logged In To Read A Private Message.<br><br>Click <A href='login.php'>HERE</a> To Login.<br>";

  }
?>


<?


function BBCode($Text)
    {




            $Text = nl2br($Text);


            $URLSearchString = " a-zA-Z0-9\:\&\/\-\?\.\=\_\~\#\'";

            $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";


            $Text = preg_replace("(\[url\]([$URLSearchString]*)\[/url\])", '<a href="$1">$1</a>', $Text);
            $Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
            $Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);

            $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $Text);
            $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);


            $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<b>$1</b>',$Text);


            $Text = preg_replace("(\[i\](.+?)\[\/i\])is",'<I>$1</I>',$Text);


            $Text = preg_replace("(\[u\](.+?)\[\/u\])is",'<u>$1</u>',$Text);


            $Text = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$Text);


            $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);


            $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);


            $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);


            $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
            $Text = str_replace("[*]", "<li>", $Text);
             $Text = preg_replace("(\[quote\](.+?)\[\/quote])is",'<center><table class="quotecode"><tr row="forumrow"><td>Quote:<br>$1</td></tr></table></center>',$Text);
            $Text = preg_replace("(\[code\](.+?)\[\/code])is",'<center><table class="quotecode"><tr row="forumrow"><td>Code:<br>$1</td></tr></table></center>',$Text);


            $Text = preg_replace("(\[font=(.+?)\](.+?))","<font color=\"$1;\">$2",$Text);
            $Text = preg_replace("(\[\/font\])","</font>",$Text);




            $Text = preg_replace("/\[img\](.+?)\[\/IMG\]/", '<img src="$1">', $Text);
            $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);

            $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);

        return $Text;
	}
?>

 

The problem is that say I posted this on WritePm.php:

 

Hello.

 

test.

 

And I received it myself and opened it up on readpm.php, I'd see:

 

Hello.rntest.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.