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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:09:24+00:00 2026-06-13T22:09:24+00:00

Having lines (01) Some text (10) Foo Bar (11) ? (13) Foo Bar (13)

  • 0

Having lines

(01) Some text
(10) Foo Bar
(11) ?
(13) Foo Bar
(13) ?
(20) Something else

check 4 rows in a batch. If row 1 and 3 are the same and row 2 and 4 are (XX) ?, then replace rows 2-4 with ... so it results as

(01) Some text
(10) Foo Bar
...
(20) Something else

Code:

$arr = explode("\n", $t);
if ( count($arr) > 3 )  {
    for ($i=1; $i<count($arr); $i++) { // check 4 rows
        if( ($arr[$i-1] == $arr[$i+1]) // if row 1 and 3 are the same
           && preg_match('/\(\d+\) \?$/', $arr[$i]) // and row 2 is "(XX) ?"
        && preg_match('/\(\d+\) \?$/', $arr[$i+2])  // and row 4 is "(XX) ?"
       ) {
            print "Match!"; //test. later replace rows 2-4 with a row "..."
         }
     }
}

This currently gives me an offset error.

Test: http://codepad.viper-7.com/iMO3BW

How could this be solved?

  • 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-13T22:09:25+00:00Added an answer on June 13, 2026 at 10:09 pm

    Use regex pattern

    ^(\(\d+\)\s+)(.*)[\n\r]\(\d+\)\s+\?[\n\r]\(\d+\)\s+\2[\n\r]\(\d+\)\s+\?[\n\r]
    

    with multiline and global modifiers.


    See this regex test.

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

Sidebar

Related Questions

I'm having difficulty combining some lines in a comma delimited text file if the
Every day we get a flat text file. Some days there are lines in
I'm having some trouble trying to animate some text around a circular path in
I have a DIV element with fixed width having some text which doesn't have
I am trying to use regex to parse out some lines from text read
I am having problems with text with multiple lines not reformatting properly when I
I have a Text File having following lines 1) 2,3 3,2 4,5 2) 1,3
Hey guys I've been having some trouble skipping some unnecessary lines from the txt
I am having a Xpage with some links. One of my link call EXIT
I am having some trouble determining if two line segments are collinear because of

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.