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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:47:46+00:00 2026-06-12T23:47:46+00:00

How can I stop explode function after certain index. For example <?php $test=The novel

  • 0

How can I stop explode function after certain index.
For example

    <?php
        $test="The novel Prognosis Negative by Art Vandelay expresses protest against many different things. The story covers a great deal of time and takes the reader through many different places and events, as the author uses several different techniques to really make the reader think. By using a certain type of narrative structure, Vandelay is able to grab the reader’s attention and make the piece much more effective and meaningful, showing how everything happened";

    $result=explode(" ",$test);
    print_r($result);
?>

What if want to use only first 10 elements ($result[10])
How can I stop explode function once 10 elements are filled.

One way is to first trim the string upto first 10 spaces (” “)

Is there any other way, I don’t want to store the remaining elements after limit anywhere (as done using positive limit parameter)?

  • 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-12T23:47:47+00:00Added an answer on June 12, 2026 at 11:47 pm

    What’s about that third parameter of the function?

    array explode ( string $delimiter , string $string [, int $limit ] )

    check out the $limit parameter.

    Manual: http://php.net/manual/en/function.explode.php

    An example from the manual:

    <?php
    $str = 'one|two|three|four';
    
    // positive limit
    print_r(explode('|', $str, 2));
    
    // negative limit (since PHP 5.1)
    print_r(explode('|', $str, -1));
    ?>
    

    The above example will output:

    Array (
    [0] => one
    [1] => two|three|four ) Array (
    [0] => one
    [1] => two
    [2] => three )

    In your case:

    print_r(explode(" " , $test , 10));
    

    According to the php manual , when you’re using the limit parameter:

    If limit is set and positive, the returned array will contain a
    maximum of limit elements with the last element containing the rest of
    string.

    Therefore , you need to get rid of the last element in the array.
    You can do it easily with array_pop (http://php.net/manual/en/function.array-pop.php).

    $result = explode(" " , $test , 10);
    array_pop($result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can stop all processes in a certain directory through
How can i stop propagation for link? <script src=http://code.jquery.com/jquery.min.js></script> <script> $(function() { $(#g).click(function(event){ alert(Link
i'm looking for equivalent of STAssertTrue, STAssertFail... but they can stop the test when
In my chrome extension i was checking for a function which can stop my
Does anybody know how I can stop this Plugin after it unscrambles the text?
Is there any way I can stop python.exe from closing immediately after it completes?
Is there any method so that I can stop syncing to gmail. I want
I have looked and tried but don't see where I can stop some being
I'm trying to write a program that can stop and start services using SilverLight
How can I stop an anchor tag redirecting to another page if the user

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.