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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:47:31+00:00 2026-05-30T07:47:31+00:00

I am trying to grab numeric value(ie 105) using preg_match from html page, please

  • 0

I am trying to grab numeric value(ie 105) using preg_match from html page, please check my html code following…

<p>
                External Backlinks
            </p>
            <p style="font-size: 150%;">
                <b>105</b>
            </p>

And i have using following regex…

$url = 'http://www.example.com/test.html';

preg_match('#<p>External Backlinks</p><p style="font-size: 150%;"><b>([0-9\.]+)#', file_get_contents($url), $matches);

echo $matches[1];

But its not returning correct value, please help to fix up the above regex. thanks.

  • 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-30T07:47:32+00:00Added an answer on May 30, 2026 at 7:47 am

    I don’t recommend using regex to parse HTML. Use a DOM parser instead. Read this rant for more information about why 🙂

    To answer your question. Here’s a working regex for your example:

    <p>[^E]*External Backlinks[^<]*<\/p>[^<]*<p style="font-size: ?150%;">[^<]*<b>(\d+)<\/b>[^<]*<\/p>
    

    It’s ugly, but it works… Don’t use it.

    preg_match('#<p>[^E]*External Backlinks[^<]*<\/p>[^<]*<p style="font-size: ?150%;">[^<]*<b>(\d+)<\/b>[^<]*<\/p>#', file_get_contents($url), $matches);
    
    echo $matches[1];
    

    Output:

    105
    

    The problem with your regex was that it didn’t account for the whitespaces in the HTML source, and you didn’t escape your slashes.

    If the source looked something like this:

    <p>External Backlinks</p><p style="font-size: 150%;"><b>105</b></p>
    

    Yours would have worked, however not very robust. (Tho I guess one could argue using regex to parse HTML is never very robust.)

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

Sidebar

Related Questions

Im trying to grab a HTML source code from a webpage which needs user
i am trying to grab links from the Google search page. i am using
Hi I am trying to grab a div from another website using JS. I
I'm currently trying to grab a file from an external url that has an
I am trying to grab a value from a url: http://localhost:8080/bin/task_status?id=2&cmd=percent_done I am unsure
I'm trying to grab out some information from Active Directory using Powershell, but I
I'm trying to grab data from a JSON on an external site but the
I am trying to grab some data from Delicious, using URL class, URL url
So I'm trying to grab the current URL of the page using Java's request
I am trying to grab just a single value from some json and am

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.