[Solved] How do I parse out HTML body text?
Posted: Wed Mar 31, 2004 10:43 am
I have a simple enough html file (myfile.html). It looks something like this:
<html>
<head>
<meta...>
<link...>
<title>...</title>
<style>...</style>
</head>
<body>
<h>ABC</h>
<p>XYZ</P>
</body>
</html>
I read this in my php code, such as:
<?php
$file='myfile.html';
$fp=fopen($file, 'r');
$contents = fread ($fp, filesize ($file));
close ($fp);
?>
But instead of reading entire file, I only want to read the portion in html <body>..</body>. Further more, I want to parse out text in <h>...</h> vs. <p>...</p>.
Can anyone provide an example of how to do this? Thanks much.
<html>
<head>
<meta...>
<link...>
<title>...</title>
<style>...</style>
</head>
<body>
<h>ABC</h>
<p>XYZ</P>
</body>
</html>
I read this in my php code, such as:
<?php
$file='myfile.html';
$fp=fopen($file, 'r');
$contents = fread ($fp, filesize ($file));
close ($fp);
?>
But instead of reading entire file, I only want to read the portion in html <body>..</body>. Further more, I want to parse out text in <h>...</h> vs. <p>...</p>.
Can anyone provide an example of how to do this? Thanks much.