Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem: Textarea \r\n
Old 01-05-2010, 01:27 PM Problem: Textarea \r\n
Stephen.'s Avatar
Average Talker

Posts: 22
Name: Stephen
Trades: 0
Firstly, I'd like to say I have been reading the forums and I know there's a lot posted on this subject. However to the best of my knowledge there isn't a direct answer to my problem.

Basically I have a 'Send Private Message' page. The user enters a name, subject and message, It tries to send (using a form php on that page) but if it fails, all the data is put back into the fields.

Here is my code:
Code:
<?
include "header.php";
$to1 = $_GET['to'];
$subject1 = $_GET['subject'];

if(isset($_POST['send'])){
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = $_POST['team'];

$cuser = mysql_query("SELECT * from `". $LID ."_teams` where `name` = '$to' and `aval` = '0'");
if(mysql_num_rows($cuser) > 0){
$team = mysql_fetch_array($cuser);
mysql_query("INSERT into `". $LID ."_mail` (`subject`, `message`, `to`, `from`) VALUES('$subject', '$message', 

'$team[id]', '$user[team]')");
echo 'Message Sent!';
}else{
echo 'Team does not exist.';
$to1 = $to;
$subject1 = $subject;
$message1 = $message; // THIS IS WHERE I WAS TRYING TO STRIP THE \R\N
}}

echo '<table width="50%" cellspacing="0"><tr>
<td width="25%"><form method="POST">To:</td>
<td width="75%"><input type="text" name="team" value="'. $to1 .'"></td>
</tr><tr>
<td>Subject:</td>
<td><input type="text" name="subject" value="'. $subject1 .'"></td>
</tr><tr>
<td>Message:</td>
<td><textarea name="message" style="width:100%" rows="6">'. $message1 .'</textarea></td>
</tr><tr>
<td colspan="2"><center><input type="submit" value="Send" name="send"></td>
</tr></table>';

include "footer.php";
?>
I've tried using str_replace and nl2br but neither seemed to work unfortunately

Thank you in advance,
Stephen
Stephen. is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-05-2010, 04:20 PM Re: Problem: Textarea \r\n
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
If you are wanting to strip newlines, then you can use the following logic:
$value = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $value);

If not, textarea will automatically display newlines, just filter your output value using htmlentities()
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-06-2010, 01:41 AM Re: Problem: Textarea \r\n
Stephen.'s Avatar
Average Talker

Posts: 22
Name: Stephen
Trades: 0
Didn't work, I'm trying to change the \r\n into an actual new line. I don't understand why it won't work. I tried the methods you said before then retried them just now.

Basically the $message string is coming from $_POST['message'];
And displaying pretty much straight away, just I can't seem to format it!

Thanks for the reply =]
Stephen. is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 12:36 PM Re: Problem: Textarea \r\n
Stephen.'s Avatar
Average Talker

Posts: 22
Name: Stephen
Trades: 0
No solution?
__________________
Did I help you? If so add to my Talkupation! =]
Stephen. is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem: Textarea \r\n
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30778 seconds with 12 queries