Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:26:42+00:00 2026-05-27T09:26:42+00:00

I have a div which has a fluid width, thus I cannot predict its

  • 0

I have a div which has a fluid width, thus I cannot predict its size in PHP. If someone enters a long string which isn’t delimited by spaces anywhere, the browser will stretch the page, and that gets quite annoying rather quickly. I have tried to use the wordwrap function for this, but I can never find the proper width and I am having issues with output.

Here’s what I am trying, based on a comment left on the documentation page for wordwrap:

<?php
//Using &#8203; here allows the browser to break the line of text, without the visual distraction. 
$line = wordwrap($line, 10, "&#8203;", true);
?>

The comment goes on to explain how it’s a Zero Width Space character, which will tell the browser it is free to break but doesn’t show up.

I’m sure you can already see the two problems which have arisen. It will replace normal spaces with that zero width space as well, so I wind up with things like: This is a​test.​Hello,​Stackoverf​low! This​ought to​trigger a​couple of​breaks.

I also coded a small bbcode parser for this, and it also breaks my html output since it cuts the tags.

On the plus side, incredibly long words are broken as expected!

I’ve tried setting various overflow properties on the div in CSS, but none of them function as expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:26:43+00:00Added an answer on May 27, 2026 at 9:26 am

    There is a CSS property of:

    word-wrap: break-word;
    

    Otherwise if you want to keep this PHP, Idealy you only want to apply a break on words with character counts greater than X, This will split the string on the space and apply a check to each word. You may run into problems with links, but you could easily check for starting url characters or apply a regex.

    $text = 'this text is fine but waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay long stuff gets broken waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay  up into bits';
    
    if($array = explode(' ',$text) and is_array($array))
    {
      foreach($array as $key => $value)
      {
        if(strlen($value) > 10)
          $array[$key] =  wordwrap($value, 10, "&shy;", true);
      }
      $text = implode(' ',$array);
    }
    
    echo $text;
    

    In this example words with a length greater than 10 are then word wrapped with the &shy; character, which is pretty useful as it produces a soft hyphen on breaks. Replace it with your breaking character if you would perfer no additional hyphens. You can also try the word wrap with a lower number than the max length before breaking, IE strlen > 20, word wrap at 10

    Sample: https://i.stack.imgur.com/qVHCA.png

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div called images_box which has a width of 277px . Within
I have a parent div id=A which has a width of 100%. I want
I have a div which has width of say 200px. It does not show
I have a div.one which has a fixed size and a background color. Within
I have div which has three buttons as, <div id=buttons> <input id=preview class=ButtonStyle type=submit
I have a div which has some text, but according to different situations this
I have DIV element which only has a few lines in and a background
I have a div (article) which has two childs (header and #content_outer). Header has
I have a menu div which has a dark background. Inside it, I have
I have a div class named switch control which has a div class named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.