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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:45:55+00:00 2026-06-03T12:45:55+00:00

Hello and thank for looking at my question. I’m in need to grab some

  • 0

Hello and thank for looking at my question.
I’m in need to grab some data from an HTML snippet.
This source is a trusted/structured one so I think it’s OK to use regex in this HTML. Dom and other advanced features in php are an overkill I guess.

Here is the format of the HTML snippet.

<div id="d-container">
  <div id="row-custom_1">
     <div class="label">Type</div>
     <div class="content">John Smith</div>
     <div class="clear"></div>
  </div>
</div>

In above, please note the first 2 DIV tags have IDs set. There could be several row-custom_1 like div tags so I will need to escape them.

I’m actually very poor in regex so I’m expecting a help from you to rab the John Smith from above html snippet.

It could be something like

<div * id="row-custom_1" * > * <div * class="content" * >GRAB THIS </div>

but I don’t know how to do it in regex.
John Smith part won’t contain any html for sure. it’s from a trusted source that it strips all html and gives the data in above format.

I can understand that regex is never a good idea to process HTML anyway.
Thank you very much for any assistance.

Edit just after 30 minutes:
Many of the awesome people suggested to use an HTML parser so I did ; worked like a charm. So if anyone comes here with a similar question, as the stupid question author, I’d recommend using DOM for the job.

  • 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-03T12:45:58+00:00Added an answer on June 3, 2026 at 12:45 pm

    Here is a simple DOM based code to get your value from the given HTML:

    $html = <<< EOF
    <div id="d-container">
      <div id="row-custom_1">
         <div class="label">Type</div>
         <div class="content">John Smith</div>
         <div class="clear"></div>
      </div>
    </div>
    EOF;
    $doc = new DOMDocument();
    libxml_use_internal_errors(true);
    $doc->loadHTML($html); // loads your html
    $xpath = new DOMXPath($doc);
    $value = $xpath->evaluate("string(//div[@id='d-container']
             /div[@id='row-custom_1']/div[@class='content']/text())"); 
    echo "User Name: [$value]\n"; // prints your user name
    

    OUTPUT:

    User Name: [John Smith]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose file1 looks like this: bye bye hello thank you And file2 looks like
I have been looking all over the Internet for an answer to this question
Question Answer below Hello I'm looking a simple way to change the colour of
Hello i dont know if this is related to a previous question that i
Hello sorry if this may be a stupid question, I am gonna try a
Hello everyone and thanks for viewing this question :) I am an indie to-be-developer
I'm looking for some help with the following. This will be a very general
Hello and thanks to everyone for reading my question. I've been working on a
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on
Ok, so my question is something I have been looking for for a while.

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.