Jump to content

[SOLVED] Textarea and PHP. <br />, \n, \r. Help?


Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/68970-solved-textarea-and-php-n-r-help/
Share on other sites

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.

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    /  >.

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.

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

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;..."

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.