Question:

PHP line breaks question

by  |  earlier

0 LIKES UnLike

Hello,

I'm creating a line break feature in my website. When users make a comment, it is stored in a database, and all comments are refreshed when the page is reloaded. My one issue is formatting the text for the comments. Using prefferably PHP, can anyone recommend a method for inserting a line break (<br>) every 20 characters before submitting the text to the database?

Thanks,

Legs

 Tags:

   Report

2 ANSWERS


  1. Because users can change the size of font in their browser I would recommend adding the text as a single line and using the css to format the containers when text is wrapped.  This may require you to redo some of the web page, but it would save you alot of headaches before you finish your web site.

    If you really want to do it the way you planned I would recommend adding linebreaks when removing it from the database rather than when putting it in.  This would let you save text intact the way it&#039;s meant to be read and save you the hassle of changing the records if you change the way it&#039;s read.

    You would do it by using the wordwrap(0 function explained below.

    http://www.w3schools.com/PHP/func_string...


  2. You could use a while (not end of string) loop with a counter to index into the string to insert a line break at that index to insert your line breaks.  See php.net (link below) for details on all of your available string functions.

    However, I strongly suggest, instead of artificially formatting by modifying the data (which will probably lead to bugs and/or headaches in the future), that you use HTML and CSS (div tags and/or tables with styles) to format your comments on the page.  Then, to change the formatting, all you have to do is change the CSS file (and/or HTML, depending on how you design it), rather than your database records.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions