SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How does one get the same line wrap in Php

    Hello,

    1st some background: We run an online news magazine where the news is reported by the People.

    So people can load the articles from their PC, Laptops, any device with a Web connection.
    This means our reporters have all different size Web browsers & Screens.
    Also they can add fotos to the articles which fotos are floated using CSS.

    The problem that we are trying to address is how to get the same consistent line wrapping, keeping in mind that we parse the article to hyperlink any included URLs. An example would best describe the problem we are having, please look here:

    http://www.realnewspost.com/sa.php?a=63177

    as you can see the lines are not wrapping the same for the 1st few paragraphs and thus causing awkward display of the text. Well this awkward gap in the lines consists through out our article pages but is worse regarding lines that are next to CSS floating images.

    Do you have suggestion as to what we can do to cause the lines to wrap nicely. No matter where our reporters clicked on the Enter key to cause a new line since again we have no control over the reporter since they are the public at large.

    ThanX.

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Member
    Join Date
    Apr 2013
    Location
    Oregon
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your data is nasty. Clean it up.

    Your post likely includes some weird characters, probably a new-line symbol everynow and then. This is what is causing all the line-breaks.

    You should be able to fix this by copy-pasting into a plain-text editor like notepad, and then copy/pasting back into your file and re-saving over itself. In the long-run though, you need to make sure your data is clean.'

    EDIT: Okay, re-read your post. If your reporters are doing this, I would make sure they are composing their articles in a plain-text environment where they can't accidentally introduce odd symbols/line-breaks. Maybe they are going from Microsoft Word to Wordpress? I am not sure exactly how they may be accidentally introducing the broken characters.

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, thats the thing. We have no real control over what the People (aka Reporters) use to compose their articles.
    As this SitePoint has not control over what people use to compose their Questions & Answers.
    So just as this SitePoint still displays the Text nicely. My question is is there a way, a Php code, that will force
    the Text to display nicely, evenly, no matter what Text Editor they used to compose their articles and then
    pasted that into the RealNewsPost.com page from where they submit their Articles.

    That is the Question?

    FYI: from what I hear most People (reporters) just type their articles right into the TEXTAREA form field
    of the article submit page.



    Quote Originally Posted by keywordsear.ch View Post
    Your data is nasty. Clean it up.

    EDIT: Okay, re-read your post. If your reporters are doing this, I would make sure they are composing their articles in a plain-text environment where they can't accidentally introduce odd symbols/line-breaks. Maybe they are going from Microsoft Word to Wordpress? I am not sure exactly how they may be accidentally introducing the broken characters.

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    SitePoint Member
    Join Date
    Apr 2013
    Location
    Oregon
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats a good question. There is the method htmlentities() which returns a non-html containing version of a string. That may remove those '<br>' tags.

  5. #5
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    12
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use a responsive theme from WordPress, problem solved

  6. #6
    SitePoint Addict WebMachine's Avatar
    Join Date
    Jun 2007
    Location
    Ontario, Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using Wordpress, there is a "paste from Word" feature in the editor that you can use to clean up any
    hidden formatting from Word documents. It's in the middle of the second row of icons. Would that help?

  7. #7
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    We are not using WordPress.
    This site is entirely built inhouse with Php, MySQL, etc.

    Quote Originally Posted by mazz View Post
    Use a responsive theme from WordPress, problem solved

    Anoox search engine volunteer

    www.anoox.com

  8. #8
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    keywordsear.ch , just wanted to let you know that I tried your suggestion of
    htmlentities()
    and it does not work at all, which you can see here:
    http://www.realnewspost.com/sa_new.php?a=63177

    Anoox search engine volunteer

    www.anoox.com

  9. #9
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have to identify "real" line breaks and remove all other line breaks to let user's browsers do the proper line breaking. That's a tough job indeed. It might require you to identify the sender's software. How is the data uploaded? If by file upload you know the file's extension/application which is a good start.
    Denny Schlesinger
    web services

  10. #10
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The data is uploaded via a Web browser form, just as it is here in SitePoint.

    So the People just type in their articles in a Web browser form, that is into <textarea> field and submit it like that.

    Quote Originally Posted by captainccs View Post
    You have to identify "real" line breaks and remove all other line breaks to let user's browsers do the proper line breaking. That's a tough job indeed. It might require you to identify the sender's software. How is the data uploaded? If by file upload you know the file's extension/application which is a good start.

    Anoox search engine volunteer

    www.anoox.com

  11. #11
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    515
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WorldNews View Post
    The data is uploaded via a Web browser form, just as it is here in SitePoint.

    So the People just type in their articles in a Web browser form, that is into <textarea> field and submit it like that.
    That does make life more difficult for you. I have an idea: visit tumblr, create an account. They too accept cut and paste into a text area but a Javascript (I think) script edits the html to conform to some standard of theirs. That might give you an idea. You see, the author sees what tumblr does to their input and they can edit it until both author and script come to a standoff and the author hits the send button.

    tumblr
    Denny Schlesinger
    web services

  12. #12
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Well if you want just the text, strip_tags the text.
    If you're wanting to turn BR's into Newlines, str_replace multiple BR's into one, and then str_replace the single BR's into \n's. (or \r\n's, if you're feeling fancy)
    need to force the text into a given word wrapping? wordwrap().

    PS: Your original example looks fine to me.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Perhaps adding editor functionality to the textarea that they are typing their article in will help - for example http://www.tinymce.com/

    That will allow them to use formatting buttons to define how their article is supposed to be formatted and will hopefully discourage them from entering their own improper formatting.

    TinyMCE also has a plugin that provides a paste option that will strip out all the junk when pasting from Word.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    @WorldNews ;

    Can you post/send/upload the original "blurb" that you would like inserting and I will endeavour to use format the "blurb" correctly.

    First attempt: http://www.johns-jokes.com/downloads/sp-b/realnewspost/

  15. #15
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    FYI: The original example I gave you looks fine because we manually corrected the Text of that article.
    But of course that is not a viable option for us to manually correct all submitted articles.

    Now as to the 1st part of your answer, I played with that idea but results were worse.


    Quote Originally Posted by StarLion View Post
    Well if you want just the text, strip_tags the text.
    If you're wanting to turn BR's into Newlines, str_replace multiple BR's into one, and then str_replace the single BR's into \n's. (or \r\n's, if you're feeling fancy)
    need to force the text into a given word wrapping? wordwrap().

    PS: Your original example looks fine to me.

    Anoox search engine volunteer

    www.anoox.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •