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

  • Home
  • SEARCH
  • 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 7839093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:19:27+00:00 2026-06-02T15:19:27+00:00

I have following data extracted from the MySQL database to create labels. BREAK Name:RAJ

  • 0

I have following data extracted from the MySQL database to create labels.


BREAK

Name:RAJ
Company:ABC
Order Number:101

Order Details:
Item1
Item20
Item3

BREAK

Name:RAJ
Company:ABC
Order Number:101

Order Details:
2 x Item1
2 x Item2
2 x Item3

BREAK

Name:RAJ
Company:ABC
Order Number:101

Order Details:
5 x Item4
5 x Item5
5 x Item2

I wrote some code to find the position of BREAK in PHP and it can generate lines number like below.

2
14
26
36

I want a file for the contents that are between line 2 and 14 in one file and 26 to 36 in one file. I am working in php and tried using sed from shell_exec function however if I read this output and generate sed command, I don’t get first 2 number together.

What I am expecting is below.

sed -n 2,14p file1.txt
sed -n 26,36p file2.txt

Any suggestion either in php or shell script?

  • 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-02T15:19:29+00:00Added an answer on June 2, 2026 at 3:19 pm

    Use array_slice() for getting ranges in an array.
    My solution is very hard coupled to your requirements, meaning every first line is a starting range number and the following the end range.

    // the lines from which will be read
    $lines = "1
    5
    16
    26";
    // split these numbers above into an array
    $lines = explode(PHP_EOL, $lines);
    
    // the source file where the ranges will be taken off
    $file = file('file.txt');
    
    
    for($i = 0; $i < count($lines); $i+=2) {
      $rangeStart  = $lines[$i];
      $rangeLength = $lines[$i+1] - $lines[$i];
    
      // slice out the ranges, beware the second parameter is the length not the offset!
      $ranges[] = array_slice($file, $rangeStart, $rangeLength);
    
    }
    
    print_r($ranges);
    

    But it would be a lot easier to do it automatically on your source file/text/string (?) directly, if this is possible.

    $file = file('file.txt');
    $len  = count($file);
    
    $output  = array();
    $current = array();
    for($i = 0; $i < $len; $i++) {
      $data = trim($file[$i]);
    
      if ($data != 'BREAK') {
        $current[] = $data;
      } else {
        $output[] = implode(PHP_EOL, $current);
        $current  = array();
      }
    }
    
    print_r($output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data in mysql database which is an iframe from u-tube:-
I have following data to save in database using php my data is :
I have the following data in mysql: file-id 32-534 32-536 32-537 32-584 32-594 46-865
Afternoon All, I have a dropdown list which extracts data from my SQL database
I'm building an application in Java to retrieve data from MySQL database. After executing
i have some problem to extract some data from html source. following is sniffit
i have to extract some data from a foxpro database. I found a sample
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have following data in a file called binFile 78 1 79 4 80

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.