amplexus Posted September 15, 2009 Share Posted September 15, 2009 so, I'm working to create an easy user interface for a restaurant owner to be able to edit the menu on their site as often as they want, and not have to go through me. I've set up a .txt file that they can edit - "menu.txt". and set up the code to call the contents of that file to display. I've then set up css to format the called text. pretty pretty, and simple. the real problem occurs because I want to have the menu have proper line breaks; it isn't a straight paragraph. so, I figured I could have a str_replace function do the work, to include a <br> where I need it. works great. except I have no idea how to have PHP read a line break from a .txt file so I have to have a double space (two spaces) stand in for a line break. works okay, but i would rather not have to confuse my client with a mickey mouse solution. anyone see a way around this? here's my code: <?php $menutext = file_get_contents ('menu.txt'); echo $breakup = str_replace(" ", "<br>", "$menutext"); ?> help? Link to comment https://forums.phpfreaks.com/topic/174359-str_replace-line-breaks/ Share on other sites More sharing options...
mikesta707 Posted September 15, 2009 Share Posted September 15, 2009 try nl2br() puts a HTML line break before all newline characters $menutext = file_get_contents ('menu.txt'); echo $breakup = nl2br($menutext); so whenever you do an actual newline in the text, it will do an HTML line break Link to comment https://forums.phpfreaks.com/topic/174359-str_replace-line-breaks/#findComment-919063 Share on other sites More sharing options...
amplexus Posted September 15, 2009 Author Share Posted September 15, 2009 awesome, thanks! Link to comment https://forums.phpfreaks.com/topic/174359-str_replace-line-breaks/#findComment-919078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.