PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
how can i get a text from a db that has \n or \n\r (i really don't know which one but whatever) and convert it to <br>'s so i can display it nicely on a webpage? cuz every line just sticks to the last one and so on
Returns string with '<br />' inserted before all newlines.
Note: Starting with PHP 4.0.5, nl2br() is now XHTML compliant. All versions before 4.0.5 will return string with '<br>' inserted before newlines instead of '<br />'.
str_replace() it if you don't want it for some reason.
Any single tag like <img ... /> or <input ... /> needs the "/" as Jam has said: tags in XHTML have to be closed. For example <p> should always be closed with </p> etc.
You don't have to be XHTML compliant but it's probably good practice to start writing tags this way.