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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:34:09+00:00 2026-06-09T17:34:09+00:00

i have a html like this: ……whatever very long html….. <span class=title>hello world!</span> ……whatever

  • 0

i have a html like this:

......whatever very long html.....

<span class="title">hello world!</span>

......whatever very long html......

it is a very long html and i only want the content ‘hello world!’ from this html
i got this html by

$result = file_get_contents($url , false, $context);

many people were using Simple HTML DOM parser, but i think in this case, using regex would be more efficient.

how should i do it? any suggestions? any help would be really great.

thanks in advance!

  • 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-09T17:34:11+00:00Added an answer on June 9, 2026 at 5:34 pm

    Stick with the DOM parser – it is better. Having said that, you could use a REGEX like this…

    // where the html is stored in `$html`
    preg_match('/<span class="title">(.+?)<\/span>/', $html, $m);
    $whatYouWant = $m[1];
    

    preg_match() stores an array of all the elements captured inside brackets in the regex, and a 0th element which is the entire captured string. The regex is very simple in this case, being almost a direct string match for what you want, with the closing span tag’s slash escaped. The captured part just means any character (.) one or more times (+) un-greedily (?).

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

Sidebar

Related Questions

I have a HTML like this: <div class=container> <span class=iconset></span> <!-- want to select
I have HTML code like this: <asp:LinkButton ID=AddButton runat=server OnClick=AddPatientBtn_Click> <span class=Normal>Add</span> </asp:LinkButton> I
I have html like this. <span class=gallery-open-item year-icon-Yes 2010> <a href=/year/none> </a> </span> I
i have html structure like this <div> <span class=ic> <span class=ic>12345</span> </span> </div> i
I have some HTML like this: <a class=button> <span> <span> <span class=buttonspan>Content</span> </span> </span>
I have some HTML like this: <h4 class=box_header clearfix> <span> <a rel=dialog href=http://www.google.com/?q=word>Search</a> </span>
Hi I have HTML like this <div class=header_countrys_middle> <a href=http://www.test.com title=United States><img src=/images/flags/us.gif alt=us
I have HTML like this: <a href=# class=modalInput glow rel=#newsletter >Newsletter!</a> This opens a
So I have Html like this http://trac.edgewall.org/wiki/RecentChanges (I want to create some Flash Track
I have html markup like this <button id=button1 onclick=alert='yup'></button> and I want to make

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.