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 6975271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:20:48+00:00 2026-05-27T17:20:48+00:00

I need to take an input from a WYSIWYG and break it down to

  • 0

I need to take an input from a WYSIWYG and break it down to having 33 (or approximate) characters per line. If it hits the limit, I need to insert a new line. Here is what I came up with:

for($i=0; $i < strlen($string); $i++) {
  if ($i % 33 == 0 && $i != 0) {
    $characters[] = '\r';
  }
  $characters[] = $string[$i];
}

$result = implode($characters);

This breaks HTML tags and words. I need to ignore HTML tags, and allow words to finish before breaking a line. What is a better way to achieve this?

  • 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-27T17:20:48+00:00Added an answer on May 27, 2026 at 5:20 pm

    What I would do is explode by space, then figure out the number of “words” that can fit on a line without going over 33 characters.

     $words = explode(' ', $string); // Get all the "words" into one string
     $lines = array(); // Array of the lines
     $line = array(); // One line
     for ($i = 0; $i < count($words); $i++) {
         $new_line = array_merge($line, $words[$i]); // Previous line plus this word
         $new_line_length = strlen(strip_tags(implode(' ', $new_line))); // Length of line
         if ($new_line_length <= 33) { // Is this line under 33 characters?
             $line[] = $words[$i];  // Yes, let's add this word to the line
         } else { // No, too long.
             $line[] = "\r";  // Add newline
             $lines[] = $line; // Add $line to the $lines array
             $line = array(); // Reset the line
         }
     }
     $final_string = implode('', $lines); // Put the whole thing back into one string
    

    I just did this in here and haven’t tested it, but it’s the basic general idea. Hope it helps. Good luck. 🙂

    Edit: added strip_tags() to the length check so tags won’t affect the length of the line (since they’re invisible anyway)

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

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
I need to take a 4 digit input from stdin in C such as
I need to take value from beginning of input to cursor. val() return whole
I have an executable that I need to take input from a .wav file
In my app I have programmable keyboard and I need to take input from
I need to take sequence of images as input from a folder and after
i need to take user input and make a very simple bar graph from
In my application, I need to take input from the user for a column
I need to be able to take an arbitrary text input that may have
Need to take a SELECT drop down list options and find if any of

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.