Hi all
I've used nl2br to replace line breaks in a text area with <br /> before.
Now I'm trying to do just the opposite, and can't figure out how.
Basically I want to echo in a text field some text from an html file.
I tried the following code, using str_replace:
<?php
$fp = fopen ("text.htm", 'r');
$data = str_replace("<br />", "\n\r", $fp);
echo "$data";
?>
but this doesn't work.
Could you help me?
?>
nl2br in reverse? replace<br \>with line breaks in tex
Moderator: General Moderators
-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
What you've done is tried to replace the <br /> from the file handle.
Can't do that, unfortunantly. Try print_r($fp) and you'll see why.
After you get the file handle, then you have to open the file. Try adding this code after your fopen line.
Can't do that, unfortunantly. Try print_r($fp) and you'll see why.
After you get the file handle, then you have to open the file. Try adding this code after your fopen line.
Code: Select all
$fp = fread($fp,filesize('text.htm');
//note that you're overwriting the file handle. You might want to
//change the variable of the file handle.-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm
thanks, but in the meantime I solved my problem another way: here's the code I used, which works perfect -didn't even need to use 'fopen()':
I left the $replace empty (didn't replace with '\n\r') because somehow the line breaks where already preserved from the htl to the textarea...
So this works
Code: Select all
<?php
$original = file_get_contents ("text.htm");
$search = '<br />';
$replace = '';
$new_content = str_replace ($search, $replace, $original);
echo "$new_content";
?>So this works