Solved

Parsing HTML

Posted on 2007-03-23
5
151 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
Comment Utility
$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
Comment Utility
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
Comment Utility
$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
Comment Utility
You're my hero!
0
 
LVL 11

Expert Comment

by:JamesCssl
Comment Utility
glad to help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

9 Experts available now in Live!

Get 1:1 Help Now