Solved

Parsing HTML

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
clicking to find my folders on wamp 8 44
php ajax contact form gives me undefined index error upon submission 2 69
Link Stopped Working 7 28
Insert PHP into HTML page. 7 45
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 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