Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms: text area and "\n" issue 2

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
Hello,

I have a php page that retrieves the content of a text file from a remote server (same server as the php page).
I put the contents of the file into a variable ($f_contents) and then convert it to a string. This text file is a source file for an older version of flash. The flash movie imports its contents into the swf. Anyway, the version of flash needs the <br> tag for all new lines. I want to be able to have the <br> replaced with the "\n" so that it displays in the text area exactly as it would in the swf movie. I have tried the following string replace method but all that happens is the <br> is replaced by the "\n" and the "\n" get printed litterally.

Here is the relevant sections of my code.

Code:
	$f_contents = strval($f_contents);
	$f_contents = str_replace('<br>', '\n', $f_contents);

then later on i echo the contents in this way:

Code:
<textarea name="contents" class="textContent" id="contents"><?php echo "$f_contents"; ?></textarea>

If i have:

hello world<br> this is your movie.
this litterally returns
hello world\n this is your movie.

Can someone tell me how to have the \n truly evaluated to a new lie within the text area tag?

Thanks in advance.
 
Use double quotes to surround the [red]\n [/red].


so:
Code:
  $f_contents = strval($f_contents);
    $f_contents = str_replace('<br>', [red]"[/red]\n[red]"[/red], $f_contents);

So the \n gets translated to the line break as opposed to just simple text.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i'm assuming you dont have magic quotes turned on.

what is the code you use to get the movie into a string?
 
Thanks vacunita,

Just for refference, how to I replace the "\n" with a "<br>" once the form is submitted?

i used the following code
Code:
$contents = str_replace("\n", '<br>', $contents);
it just added the <br> to the end of the line, but did not remove the carraige return so that all the text is on the same line. I sm not sure if carriage return is the right term.

jpadie,
what is the code you use to get the movie into a string?
The string comes from the contents of a text file that is loaded into the swf. I am just interested in the contents of the text file here, I use actionscript to bring the text content into flash.
 
Glad I could help.

FYI "carriage return" is the right term.

And the change from "\n" to "<br>" Whe the text is submitted the textarea adds an "\r" at the end of the lines. so you have to replace it also like so:

Code:
$contents = str_replace("[red]\r[/red]\n", '<br>', $contents);

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Just for refference, how to I replace the "\n" with a "<br>" once the form is submitted?

i would use the nl2br() function

also, unless you can be certain that your flash movie contains only old html i would jig the str_replace like this:

Code:
$search = array ("<br>", "<br/>", "<br />","<BR>","<BR/>","<BR />");
$contents = str_replace ($search, "\r\n", $contents);
 
thanks guys, it all works great,

stars all around

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top