Kelvie Posted September 12, 2007 Share Posted September 12, 2007 Hello. I am trying to make a mailing system on my website, but I'm having a bit of trouble. The problem I am having goes something like this: The user inputs their message, subject, and recipient. The message is stored using nl2br() function. The recipient views the message fine, the < br />'s display correctly etc. The recipient wishes to reply, so he hits the 'reply' button. The information is received and this code is run: <?php if($_GET[REPLYID]){ $dataM = $_GET[REPLYID]; $replyq = MYSQL_QUERY("SELECT * FROM *REMOVED* WHERE `*REMOVED*`='*REMOVED*'"); $replyd = @MYSQL_FETCH_ARRAY($replyq); if($_GET[ACTION]){ ?><script type="text/javascript">idfields.to.value = "<?php echo $replyd[*REMOVED*]; ?>"; idfields.subject.value = "RE: " + "<?php echo $replyd[*REMOVED*]; ?>"; idfields.text.value = "<?php echo $replyd[*REMOVED*]; ?>";</script><?php } } // -------- code continues. Ok, so pretty much what this does is if the action is reply it fills in the 'TO' and 'SUBJECT' functions automaticcaly, saving the 'replyee' time. Now, the problem I am having is with my textarea. I am attempting to get the textarea to display ---> 'user wrote' : then the old message here. I have tried getting it to do this by just grabbing the message that was received and displaying it in the textarea feild, but the feild doesn't seem to like the '< br />'s created by nl2br() function. How can I get the textarea to replace the < br />'s in the message with empty lines? I want to keep the old messages format. The textarea doesn't seem to understand \n or \r either. If I wasn't clear please ask, I really need to figure this out I've tried everything. -Aaron Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/ Share on other sites More sharing options...
btherl Posted September 12, 2007 Share Posted September 12, 2007 Textarea should understand \n, or perhaps \r\n together. Have you checked the source of your page to ensure that the new lines are shown in the source? Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346681 Share on other sites More sharing options...
Kelvie Posted September 12, 2007 Author Share Posted September 12, 2007 I've tried simply going <?php echo "Testing \r\n testing."; ?> in the message feild. It just displays \r\n and no line break appears. Same deal with < br /> A perfect example of what I need to be done can be reproduced by simply pressing 'modify' on your post when you have empty lines. It displays the text along with whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346684 Share on other sites More sharing options...
feuerfalke Posted September 12, 2007 Share Posted September 12, 2007 Put your content through this function (originally gotten from PHP.net documentation user notes... on the function nl2br I think): function br2nl($content) { $content = preg_replace("/(\r\n|\n|\r)/", "", $content); return preg_replace("=< *br */? *>=i", "\n", $content); } It will also replace any <br />s the user put in, even if they did something stupid like < br / >. Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346686 Share on other sites More sharing options...
btherl Posted September 12, 2007 Share Posted September 12, 2007 Try this: <textarea ><?php echo "Testing \r\n testing."; ?> </textarea> Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346688 Share on other sites More sharing options...
Kelvie Posted September 12, 2007 Author Share Posted September 12, 2007 Ok, ill put that on my server now. Do you have MSN or antyhing that could make this easier to fix? Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346689 Share on other sites More sharing options...
Kelvie Posted September 12, 2007 Author Share Posted September 12, 2007 It worked. Thanks Ok something i just noticed, idfields.text.value = "<?php echo $replyd[message]; ?>";</script> I dont need to use JS to do that, I can just place it directly in the textarea like you showed me. I still need to convert the <br>'s to \r\n.. will that regex that was given do that? I'm not familiar at all with regex so just checking. Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346691 Share on other sites More sharing options...
nadeemshafi9 Posted September 12, 2007 Share Posted September 12, 2007 ok these are from ASP, but try removing them especialy the first one, make sure u try removing **** vbcrlf ****** desc = replace(RS("description"), vbcrlf, " ") desc = replace(desc, "'", " ") desc = replace(desc, "\n", " ") desc = replace(desc, "<br>", " ") desc = replace(desc, "<b>", " ") desc = replace(desc, "</b>", " ") desc = replace(desc, "<p>", " ") desc = replace(desc, "</p>", " ") desc = replace(desc, "<strong>", " ") desc = replace(desc, "</strong>", " ") desc = replace(desc, "\r", " ") desc = replace(desc, "\s", " ") desc = replace(desc, """", " ") desc = split(desc, " ") i had this prob in ASP when trying to insert into alt text Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346693 Share on other sites More sharing options...
Kelvie Posted September 12, 2007 Author Share Posted September 12, 2007 Ah excellent! I got it working guys. Thanks very much for your help. I got one more question; is there anyway to change pages in PHP other than using something like <?php echo '<meta http-equiv="refresh" content="1;URL=rpg.php?RPG=mail" />';?> ?? I've noticed that sometimes it can refresh the actual page the script is on before it changes to new page, even with content="0;..." Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346699 Share on other sites More sharing options...
jitesh Posted September 12, 2007 Share Posted September 12, 2007 set header with this headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346703 Share on other sites More sharing options...
Kelvie Posted September 12, 2007 Author Share Posted September 12, 2007 woah that totally lost me, where do i place the URL to goto?? Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346706 Share on other sites More sharing options...
btherl Posted September 12, 2007 Share Posted September 12, 2007 I think jitesh misunderstood your question. To redirect via headers: header("Location: http://site.com/page.php"); exit(0); or header("Location: /page.php"); exit(0); The exit isn't necessary, but there's usually nothing much worth doing if you're going to do an immediate redirect. This redirect occurs at the HTTP level, which means the browser will never display the page. Instead it will do the redirect before displaying anything. Meta refresh will display the page and THEN redirect. Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346713 Share on other sites More sharing options...
marft Posted September 12, 2007 Share Posted September 12, 2007 Hello guys, I have a similar problem with the text wrap. I hav ethe following code which generates the output: $customer = xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br />'); I have inserted your code: <textarea name="select1" rows=5 cols=30 > <?php $customer = xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br />'); function br2nl($customer) { $customer = preg_replace("/(\r\n|\n|\r)/", "", $customer); return preg_replace("=< *br */? *>=i", "\n", $customer); } echo $customer; ?> </textarea> But it doesn't work. The output in the textarea is Name Surname <br />Street No.<br />00000 Town<br />Country Could you please help me? Thanks in advance. Marcel Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346722 Share on other sites More sharing options...
marft Posted September 12, 2007 Share Posted September 12, 2007 Okay, I got it: <textarea name="select1" rows=5 cols=30 > <?php $customer = xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br />'); //function br2nl($customer) { $customer = preg_replace("/(\r\n|\n|\r)/", "", $customer); echo preg_replace("=< *br */? *>=i", "\n", $customer); //} //echo $customer; ?> </textarea> But now I'm searching for how I can replace blanks, because in the textarea output are a lot of blanks in front of the name. I tried $customer = preg_replace("/ /", "", $customer); ... but it doesn't work. Marcel Quote Link to comment https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/#findComment-346735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.