Line breaks problem :(
Posted: Mon Oct 30, 2006 4:55 pm
feyd | Please use
This is my PHP code:[/syntax]
Thank you so much in advanced!!!
p.s.
The breaks are added, I see /n at the end of every line, but the enters still exist in the file created alongside to the /n's
EDIT: PLEASE NOTE I -DID- USE nl2br BUT IT DIDN'T WORK AS EXPECTED
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi guys, I wrote a code that reads what a user typed in a textarea created via HTML and creates a new file called yourfile.js with the text that the user typed in the textarea. My only problem is that when the user hits the return key on the keyboard (AKA enter) the new file contains moves to the next line. I can't have that because the a variable is being loaded from javascript from that file, and java script cannot have more than one continuous line in the var. I want to convert the new lines (enters) to br, /n or something like that, so far unsuccessfully. This is my HTML code with my textarea:
[syntax="html"]
<html>
<body>
<form action="form.php" method="post">
<textarea name="info" wrap="off"></textarea>
<input type="submit">
</form>
</body>
</html>
Code: Select all
<html>
<body>
<?php
$myFile = "yourfile.js";
$information = $_POST['info'];
$fh = fopen($myFile, 'w') or die("can't open file");
$information = nl2br($information);
$information = str_replace("<br />","/n", $information);
fwrite($fh, $information);
fclose($fh);
?>
</body>
</html>p.s.
The breaks are added, I see /n at the end of every line, but the enters still exist in the file created alongside to the /n's
EDIT: PLEASE NOTE I -DID- USE nl2br BUT IT DIDN'T WORK AS EXPECTED
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]