Taking PARAGRAPH input from a html form and saving in a PHP
Posted: Sun Mar 13, 2005 11:31 am
Hey guys,
I'm trying to take a data paragraph input from a form variable named instructions, and then put it into a form where it can be saved in a php variable named $instructions.
I fixed the error when someone inputs something in "Text" and it automatically string replaces the " with \", It would be nice if I knew how to make it so if it was ALREADY \" escaped, then it wouldn't do it again and right now it makes it \\", now I just need to correct the input format so when there are returns, that it inserts a <br> at the END of the line, and then goes to a new line. here is what I have
When I input this:
I have tried things like this:
feyd | Please use
I'm trying to take a data paragraph input from a form variable named instructions, and then put it into a form where it can be saved in a php variable named $instructions.
I fixed the error when someone inputs something in "Text" and it automatically string replaces the " with \", It would be nice if I knew how to make it so if it was ALREADY \" escaped, then it wouldn't do it again and right now it makes it \\", now I just need to correct the input format so when there are returns, that it inserts a <br> at the END of the line, and then goes to a new line. here is what I have
Code: Select all
<?
if($_POST["instructions"]){ $instructions = $_POST["instructions"]; }
$instructions = str_replace("\n", "\n\n", $instructions);
$instructions1 = str_replace("\n", "<br>\n", $instructions);
$instructions2 = str_replace("\n<br>", "<br>", $instructions1);
$instructions3 = str_replace("\n\n", "\n", $instructions2);
$instructions = str_replace('"', '\"', $instructions3);
?>I get this in the $instructions variable:Description of the game and more
What are you doing? How'd you like some muffins? Test this "out" you kl....
Test
And what I WANT is this EXACTLY:Description of the game and more
<br>
<br>
What are you doing? How'd you like some muffins? Test this \"out\" you kl....
<br>
<br>
Test
I want those extra end lines (\n I think?) deleted and it only has a end line at the end of the line totally. Can I get some help?Description of the game and more<br><br>
What are you doing? How'd you like some muffins? Test this \"out\" you kl....<br><br>
Test
I have tried things like this:
But it doesn't work like I was expecting.$instructions = str_replace("\n<br>([\n]{1,5})<br>", "<br><br>\n", $instructions);
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] :grumble-grumble:[/color]