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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:36:40+00:00 2026-06-03T11:36:40+00:00

I have some Plain Text/HTML Content like so: Title: Lorem ipsum dolor sit amet,

  • 0

I have some Plain Text/HTML Content like so:

Title: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Category: Lorem ipsum dolor sit amet, consectetur adipiscing elit.

and i want to match only the line where it says “Snippet: and the text that follows it, BUT ONLY on that line, nothing else, and also making the search case-insensitive. I tried with regular expressions, but ultimately i want to attempt using DOMDocument now, how can i do this?

  • 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-03T11:36:41+00:00Added an answer on June 3, 2026 at 11:36 am

    I don’t know some details about your problem, so my answer might not be appropriate. You could decide based on the size of the content you need to parse that this is not an option. Also, from the question it is not clear where the html content comes into place, that is why I wrote this solution that doesn’t use DOM parsing.

    A possible solution might be to get the lines that you want to parse in an array. After that you can filter the array, removing the lines that don’t match your rule from the result.

    A sample would be:

    //this is the content
    $text = 'Title: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Category: Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    
    //get the lines from your input as an array.. you could acheive this in a different way if, for example, you are reading from a file
    $lines = explode(PHP_EOL, $text);
    
    // apply a cusom function to filter the lines (remove the ones that don't match your rule)
    $results = array_filter($lines, 'test_content');
    
    //show the results
    echo '<pre>';
    print_r($results);
    echo '</pre>';
    
    //custom function here:
    function test_content($line)
    {
        //case insensitive search, notice stripos; 
        // type strict comparison to be sure that it doesn't fail when the element is found right at the start
        if (false !== stripos($line, 'Snippet'))
        {
            return true;
        }
        return false;//these lines will be removed 
    }
    

    that piece of code will return only one element in the $results array, the second line

    you can see it at work here: http://codepad.org/220BLjEk

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

Sidebar

Related Questions

I have some text like $text=--e89a8f234aade3345704b8477b83 Content-Type: text/plain; charset=ISO-8859-1 this is a text. this
I have, for example, markup like this <div id=content> <p>Here is some wonderful text,
I have an XSLT file generating plain HTML. I need to wrap some elements
In an iPhone application, I have some plain C functions. Is it possible to
I have some XML which contains records and sub records, like this: <data> <record
I have an Email body that used to be plain text, but now I've
Is there some clever content-type setting that makes Firefox display highlighted HTML source code
I have an HTML content which is entered by user via a richtext editor
I'm going to be doing some webscraping and my plan is to have something
I have some files that are uuencoded, and I need to decode them, using

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.