Lumit Posted June 13, 2008 Share Posted June 13, 2008 hello, I have a small problem. I am using include() to insert text from a file into my webpage, but I don't want to have <br /> everytime I need a linebreak (I'm making a CMS) I have set the textarea's wrapping to "hard" so it is being put into the txt file correctly, but php isn't accepting it. Is there a way to get it to accept them? Or convert it? thanks, Lumit Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/ Share on other sites More sharing options...
wildteen88 Posted June 13, 2008 Share Posted June 13, 2008 Use nl2br Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565034 Share on other sites More sharing options...
Lumit Posted June 14, 2008 Author Share Posted June 14, 2008 erm... No I think you misunderstood. I have a txt file with this in it: this is on a new line! and so is this!!! But when i use include() to put it in a php document it translates into:this is on a new line! and so is this!!! I want it to just put it in there as it was in the txt file. Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565666 Share on other sites More sharing options...
Darklink Posted June 14, 2008 Share Posted June 14, 2008 Have you actually tried using nl2br. It should work. It turns invisible linebreaks into HTML. Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565680 Share on other sites More sharing options...
Lumit Posted June 15, 2008 Author Share Posted June 15, 2008 Yes, I tried using this code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head><title> example </title></head> <body> <?php $text=include("example.txt"); echo nl2br($text); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565806 Share on other sites More sharing options...
trq Posted June 15, 2008 Share Posted June 15, 2008 You might want to take a look at how include() works, it does not return a value. <?php $text = file_get_contents("example.txt"); echo nl2br($text); ?> Edit by Daniel0: Fixed bbcodes. Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565825 Share on other sites More sharing options...
Daniel0 Posted June 15, 2008 Share Posted June 15, 2008 Have you actually tried using nl2br. It should work. It turns invisible linebreaks into HTML. They're not invisible. Check the HTML source or run it from CLI... Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-565863 Share on other sites More sharing options...
Lumit Posted June 15, 2008 Author Share Posted June 15, 2008 thorpe, thank you! that worked perfectly. I was wondering how include() works but couldn't find a good description. Daniel0, huh? ??? Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-566090 Share on other sites More sharing options...
Daniel0 Posted June 16, 2008 Share Posted June 16, 2008 Daniel0, huh? ??? I was just pointing out to Darklink that regular line breaks aren't "invisible" as he said. It's just because HTML ignores extra whitespace besides a single space. Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-566175 Share on other sites More sharing options...
bluejay002 Posted June 16, 2008 Share Posted June 16, 2008 i think its about \n and \r thing. try sanitizing the code by removing \r using preg_replace(). after that display it... if it does not display properly after that... add nl2br() after the sanitation. did it work? Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-566215 Share on other sites More sharing options...
Lumit Posted June 16, 2008 Author Share Posted June 16, 2008 did it work?thorpe's code worked perfectly. Thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-566232 Share on other sites More sharing options...
Darklink Posted June 23, 2008 Share Posted June 23, 2008 I was just pointing out to Darklink that regular line breaks aren't "invisible" as he said. It's just because HTML ignores extra whitespace besides a single space. They are invisible to the user unless they view the source. I know that. Quote Link to comment https://forums.phpfreaks.com/topic/110100-linebreaks/#findComment-572649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.