Jump to content

Recommended Posts

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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.