Solved

Parsing HTML

Posted on 2007-03-23
5
155 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now