Solved

Parsing HTML

Posted on 2007-03-23
5
167 Views
Last Modified: 2013-12-13
Is it possible to parse an html page to pull a specific number off that page. The number follows immediately after the keyword "Big Number" in the following form:

Big Number:&nbsp;<b>309</b>

Is it possible to parse the page with PHP, search for that keyword, and then put the number into a variable to be stored in a database?
0
Comment
Question by:jfredrickson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18784175
$string = 'whatever here Big Number:&nbsp;<b>309</b>whateverhere'
preg_match('/Big Number:&nbsp;<b>([0-9]+)<\/b>/s',$string,$matches);
echo $matches[1];
0
 
LVL 4

Author Comment

by:jfredrickson
ID: 18784204
Cool, how do I get the html from an external URL into the $string variable to parse it?
0
 
LVL 11

Accepted Solution

by:
JamesCssl earned 500 total points
ID: 18784211
$handle = fopen("http://www.example.com/", "r");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
$string = $contents;
0
 
LVL 4

Author Comment

by:jfredrickson
ID: 18784215
You're my hero!
0
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18784218
glad to help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question