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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:36:09+00:00 2026-05-31T05:36:09+00:00

I have a sample string as shown below. In the string, how can I

  • 0

I have a sample string as shown below. In the string, how can I remove line ending with ( and remove line starting with ) and grab second word of every line?

This is some text (
some more text,
one line text,
more and more text available,
this one is even longer and even more text is available,
) this is the last line;

This is also some more text (
Second time some more text,
one line text second time ,
Once again more and more text available,
finally this one is even longer and even more text is available,
) this is the last line;

The string shown above comes from a text file. Can be either pasted in a textarea or a file could be uploaded and this text will be read from the file. So in the example shown above, expected output is:

some more text,
one line text,
more and more text available,
this one is even longer and even more text is available,

Second time some more text,
one line text second time ,
Once again more and more text available,
finally this one is even longer and even more text is available,

//words are
more
line
and
one
time
line
again
this

How to do the above in PHP?

  • 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-05-31T05:36:10+00:00Added an answer on May 31, 2026 at 5:36 am

    You can use the explode, array_map, and array_filter functions to do what you want.

    First you have to define functions to filter out the ( and ) lines, and to extract the second word of each line.

    function filter_line($line) {
        //the regular expression detects a line ending with a ( or beginning with a )
        if(preg_match('/(^\)|\($)/', trim($line))) return false;
        if(empty($line)) return false;
        return true;    
    }
    
    function map_line($line) {
        //the regular expression here splits the line into pieces at any whitespace
        //in case they used multiple spaces or a tab
        $split = preg_split('/\s+/', trim($line));
    
        //if there are one or zero words on this line then remove it from the result
        if(count($split) < 2) return false;
    
        //return the second word
        return $split[1];
    }
    

    Now that you have that, the rest is easy:

    //this will split the whole text into an array of lines
    $array = explode("\n", $myTextGoesHere);
    
    //this will return an array of entries that are either the second word or false
    $filtered = array_filter($array, 'filter_line');
    
    //at this point $filtered contains the first step.
    print_r($filtered);
    
    //finally, this will extract the second word from each line
    //and eliminate lines with less than two words
    $result = array_filter(array_map('map_line', $filtered));
    
    //$result contains the output
    print_r($result);
    

    All done.

    Incidentally, it’s clear you are trying to get type values from a CREATE TABLE statement – you might have to be a little more careful about how you parse that depending on your RDBMS.

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

Sidebar

Related Questions

Assume I have a class that looks like this: class Sample { public string
I have a sample string: <num>1.</num> <Ref>véase anomalía de Ebstein</Ref> <num>2.</num> <Ref>-> vascularización</Ref> I
Say you have a string 3.4564. A sample set in the database has these
I know this might be very easy to some,, I have a simple string
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
Can I build a class as shown below dynamically using reflection? There are no
I have a web page below to explorer, as you can see, it is
I have a feeling that this question is very simple, but I just can't
I am trying to set up a relationship as shown below. Each car can
In the sample code below, it shows that boost::tuple can be created implicitly from

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.