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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:43:56+00:00 2026-06-18T09:43:56+00:00

I want to explode a string by (for example) 50 symbols (min), but without

  • 0

I want to explode a string by (for example) 50 symbols (min), but without dividing words in 2 parts.

Is this possible?

Using str_split() will cause the last word to get split, which is what I don’t want.

Example: splitting string by 5 symbols;

$input = 'This is example, example can be anything.';

$output[0] = 'This';
$output[1] = 'is example,';
$output[2] = 'example';
$output[3] = 'can';
$output[4] = 'be anything';
  • 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-18T09:43:57+00:00Added an answer on June 18, 2026 at 9:43 am

    I don’t think there’s a single built-in function that will do it for you, but you could do something like this:

    Codepad Example Here

    $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nec elit dui, nec fermentum velit. Nullam congue ipsum ac quam auctor nec massa nunc.";
    
    $output = array();
    while (strlen($string) > 50) {
        $index = strpos($string, ' ', 50);
        $output[] = trim(substr($string, 0, $index));
        $string = substr($string, $index);
    }
    $output[] = trim($string);
    
    var_dump($output);
    
    // array(3) {
    //   [0]=>
    //   string(50) "Lorem ipsum dolor sit amet, consectetur adipiscing"
    //   [1]=>
    //   string(55) "elit. Quisque nec elit dui, nec fermentum velit. Nullam"
    //   [2]=>
    //   string(43) "congue ipsum ac quam auctor nec massa nunc."
    // }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to explode a string by parts in PHP into an array,
I am trying to split/explode/preg_split a string but I want to keep the delimiter
Is there a way to explode a string with different separators/delimiters, for example this
want to know why String behaves like value type while using ==. String s1
How can I explode a string by one or more spaces or tabs? Example:
I want to count the words in a specific string so that I can
Can we do multiple explode() in PHP? For example, to do this: foreach(explode( ,$sms['sms_text'])
I have a string like first,second[,b],third[a,b[1,2,3]],fourth[a[1,2]],sixth I want to explode it to array Array
I want to extract two consecutive words starting from each word in a string.
I have a huge text file which I want to explode into an array.

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.