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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:31:16+00:00 2026-06-08T21:31:16+00:00

I am using this $lines = explode(PHP_EOL, trim($text)); to split $text into an array

  • 0

I am using this

$lines = explode(PHP_EOL, trim($text));

to split $text into an array of lines so i can display like this:

foreach ($lines as $line) {
 echo $line;
}

but now i want to test the lenght of each $line and if lenght is over 50 chars i want to split each line in multiple of 50 chars.

How can i do this and keep all lines in the $lines array ?

I need a way to test each line or explode it using explode( wordwrap($line), 50 ); and then re-build the $lines array so i can cycle all lines again.

As I am not a coder I do not know how to insert new lines in the array if one line must be split in several pieces of 50 chars.

Hope you understand my question.
Thanks.

  • 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-08T21:31:18+00:00Added an answer on June 8, 2026 at 9:31 pm

    This is precisely what chunk_split is made for:

    echo chunk_split( $line, 50 );
    

    This’ll break your $line into multiple lines of 50 characters each.


    Update after the OP specified that he wants to split the lines into individual elements in the array:

    $temp = explode( PHP_EOL, trim($text) );
    $lines = array();
    
    foreach ($temp as $line) {
       $lines = array_merge( $lines, str_split($line, 50) );
    }
    

    See it here in action: http://viper-7.com/eRgm6p

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

Sidebar

Related Questions

I'm using this line of code to insert a value from an array into
I'm using this CSS to align a line of text (the link) with the
I have locked cells in a spreadsheet using this lines of code. Range(A1:D23).Select Selection.Locked
I am using this line of code to get two data entries from an
I'm using this line to get the beginning time of the first day of
I want to use this line of code: using (ADataContext _dc = new ADataContext(ConnectionString),
I'm using now.js and there's this line that refers to localhost. In order for
I tried using juggernaut cocoa: https://github.com/fpotter/juggernaut-cocoa Added this line to my code: JuggernautClient *client
I have a line, which is a sprite made by using this code CGPoint
My head is about to explode after looking into why this is not working

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.