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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:51:14+00:00 2026-06-13T01:51:14+00:00

I need to split a big chunk of text into paragraphs of the same

  • 0

I need to split a big chunk of text into paragraphs of the same size, with the exact same number of string lines to keep them uniforms, i’m currently doing it with php with the following code.

        function arrangeText(){
                    if (have_posts()) : while (have_posts()) :  the_post();

                    $content = strtolower(get_the_content());
                    $content = trim(strip_tags($content));
                    $post_len = strlen($content);
                    $segmentCont = 1; 
                    $auxOffset = 0; 
                    $auxOffset2 = 0;
                    $limit = 896; 
                    $limitTotal = 0;

                    while($limitTotal<$post_len){

                            if($segmentCont==2) {
                                $limit = 943;
                            }

                            $segmentCont++;
                            $limitTotal = $limitTotal + $limit;
                            if($limitTotal<$post_len)
                             { $auxOffset = strpos($content," ",$limitTotal);}
                            else 
                             { $auxOffset = $post_len;}
                            $post_segment = trim(substr($content,$auxOffset2,$auxOffset-$auxOffset2));
                            $auxOffset2 = $auxOffset;
                            echo_segment($post_segment);
                    }

                    endwhile;                       
                    endif;
                }

This actually works but even though im counting each character, some characters may take up to three character spaces, so my paragraphs get different number of lines, or the last line is sliced in half, if i use a monotypefont everything goes smoothly, but my client wants a specific font, and i’ve been trying all sort of things with no luck, so i come to you the big guys for help. The only thing i can imagine to solve this is a very complex script to get the width of each character im echoing and add that value to a counting variable each time, and do a conditional (inside a loop i guess) to check if the total width of the characters exceeds the total width of my paragraph if so slice it before the last ” “(white space) it founds(preventing the code to cut words in half), but i have no idea if this is possible with php, js, jquery or anything that can help me out on a website, im sure there is an easy way to do what i’m trying here but maybe im just not smart enough, so pls help me out =).

Edit 1: My bad, the mono-spaced font won’t do the trick either, they were getting cut and overflowing below my p tags ( overflow:hidden ) and i though they were working until i read the text, so i guess that even that they are mono-spaced, their character sizes are different too.

  • 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-06-13T01:51:15+00:00Added an answer on June 13, 2026 at 1:51 am

    You can use this code to measure widths of characters and create a “dictionary”.
    You can tweak it to return relative values (lets say w = 1, i = 0.5 so it will be more flexible).

    The fiddle is here: http://jsfiddle.net/Gw4AV/

    var chars = ["a", "b", "c", "i", "w"];
    var widths = [];
    for (var i = 0; i < chars.length; i++)
    {
        var span = $("<span>").text(chars[i]);
        $("body").append(span);
        widths.push(span.width());
    }
    alert(widths);
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to split a keyword string and turn it into a comma delimited
I need to split an flv file into chunks of the known size on
I need to split my string input into an array at the commas. Is
I need to split a string into chunks of 2,2,3,3 characters and was able
I need to split a string into two parts. The string contains words separated
I need split string by commas and spaces, but ignore the inside quotes, single
I need to split the string result of the autocomplete plugin . I know
I need to split this line string in each line, I need to get
What I'm looking to do is split data from string into an array. Here's
I have a big zipfile that I need to split in multiple zip files.

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.