473,581 Members | 6,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to extract part of HTML page

Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I end
up with a page that includes a lot of information that I don't need. Using
the PHP function strip_tags I've ended with the text below and from the
remaining HTML code, I'd like to extract the lines starting with "<TABLE
BORDER="1" WIDTH="315">" up to its closing </TABLEtag. How do I do this
using PHP? I tried using preg_match and the like but my regex skills are
pretty bad. Not too sure where to start. Could someone please provide me
with some pointers?
=============== =============== =============== =============== =============== ==============
<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text some
text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <----- extract
from here

<TR><TD>
some text some text some text some text some
text
</TD>
<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
<TR><TD>
some text some text some text some text some
text
</TD>

<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
<TR><TD>
some text some text some text some text some
text
</TD>
<TD ALIGN="right">
some text some text some text some text some
text
</TD></TR>
</TABLE>
<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some text
some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
=============== =============== =============== =============== =============== ==============
Thanks
Eric

Sep 16 '08 #1
18 3960
On Tue, 16 Sep 2008 21:42:20 +1000, Ecka wrote:
I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
With DOMDocument::lo adHTML(), you can simply do an XPath query on the
HTML.

An alternative is to split the HTML in lines, loop through the lines and
put all the lines between <tableand </tablein a string:

$lines = explode('\n', $text);
foreach ($lines as $line) {
if (preg_match('~< table~', $line)) {
$on = true;
} else if (preg_match('~</table>~', $line)) {
$on = false;
}
if ($on) $result .= $line;
}
echo $result;
Sep 16 '08 #2
r0g
Ecka wrote:
Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
=============== =============== =============== =============== =============== ==============

<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
=============== =============== =============== =============== =============== ==============

Thanks
Eric
Try this.

preg_match('#TA BLE BORDER="1"
WIDTH="315">(.* ?)?\</TABLE>#s',$sour ce,$result);
print $result[1];

Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!

Regards,

Roger.
Sep 16 '08 #3
r0g wrote:
Ecka wrote:
>Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
============== =============== =============== =============== =============== ===============

<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
============== =============== =============== =============== =============== ===============

Thanks
Eric

Try this.

preg_match('#TA BLE BORDER="1"
WIDTH="315">(.* ?)?\</TABLE>#s',$sour ce,$result);
print $result[1];
You forgot the opening "<" for the table tag. You also have a 0-1
quantifier after the first capture group, and the OP doesn't seem to
want an empty table. You have an unnecessary escape of "<" for the end
table tag.

@OP: unfortunately, this approach relies on the site authors not
changing their code. We can further minimize hard coding by using the
pre-defined space character class, and case insensitivity. The /x
modifier let's your regex ignore space and easily insert comments.

preg_match('~
<table \s+ # open table tag

# attributes
border=[\'"]1[\'"] \s+
width=[\'"]315[\'"]>

(.*?) # table body

</table# end table tag
~sxi',
$source,
$match_array
);
Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!
Very good advice.
Regards,

Roger.
--
Curtis
Sep 16 '08 #4
r0g
Curtis wrote:
r0g wrote:
>Ecka wrote:
>>Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
============= =============== =============== =============== =============== =============== =
<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
============= =============== =============== =============== =============== =============== =
Thanks
Eric

Try this.

preg_match('#T ABLE BORDER="1"
WIDTH="315">(. *?)?\</TABLE>#s',$sour ce,$result);
print $result[1];

You forgot the opening "<" for the table tag. You also have a 0-1
quantifier after the first capture group, and the OP doesn't seem to
want an empty table. You have an unnecessary escape of "<" for the end
table tag.

@OP: unfortunately, this approach relies on the site authors not
changing their code. We can further minimize hard coding by using the
pre-defined space character class, and case insensitivity. The /x
modifier let's your regex ignore space and easily insert comments.

preg_match('~
<table \s+ # open table tag

# attributes
border=[\'"]1[\'"] \s+
width=[\'"]315[\'"]>

(.*?) # table body

</table# end table tag
~sxi',
$source,
$match_array
);
>Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!

Very good advice.
>Regards,

Roger.

True enough, twas pretty slapdash, even for a usenet post ;-) For some
reason earlier my copy of php was choking on those left angle brackets
and I didn't want to spend the time figuring out why. Oddly enough
though I've just tried it with the angle brackets back in again and it
works fine now, go figure eh,! The surplus quantifier was a remnant from
an earlier attempt to step around the left bracket thing too.

Bloody regexes! I love them dearly but Zawinski had a point! :-)

Roger.
Sep 16 '08 #5

"r0g" <ai******@techn icalbloke.comwr ote in message
news:ga******** **@aioe.org...
Curtis wrote:
>r0g wrote:
<snip>
>>>>

Try this.

preg_match('# TABLE BORDER="1"
WIDTH="315">( .*?)?\</TABLE>#s',$sour ce,$result);
print $result[1];

You forgot the opening "<" for the table tag. You also have a 0-1
quantifier after the first capture group, and the OP doesn't seem to
want an empty table. You have an unnecessary escape of "<" for the end
table tag.

@OP: unfortunately, this approach relies on the site authors not
changing their code. We can further minimize hard coding by using the
pre-defined space character class, and case insensitivity. The /x
modifier let's your regex ignore space and easily insert comments.

preg_match(' ~
<table \s+ # open table tag

# attributes
border=[\'"]1[\'"] \s+
width=[\'"]315[\'"]>

(.*?) # table body

</table# end table tag
~sxi',
$source,
$match_array
);
>>Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!

Very good advice.
>>Regards,

Roger.


True enough, twas pretty slapdash, even for a usenet post ;-) For some
reason earlier my copy of php was choking on those left angle brackets
and I didn't want to spend the time figuring out why. Oddly enough
though I've just tried it with the angle brackets back in again and it
works fine now, go figure eh,! The surplus quantifier was a remnant from
an earlier attempt to step around the left bracket thing too.

Bloody regexes! I love them dearly but Zawinski had a point! :-)

Roger.
Thanks guys!

Will give them a try and report back.

Cheers,
Eric

Sep 16 '08 #6
r0g wrote:
Curtis wrote:
>r0g wrote:
>>Ecka wrote:
Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
============ =============== =============== =============== =============== =============== ==
<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
============ =============== =============== =============== =============== =============== ==
Thanks
Eric

Try this.

preg_match('# TABLE BORDER="1"
WIDTH="315">( .*?)?\</TABLE>#s',$sour ce,$result);
print $result[1];
You forgot the opening "<" for the table tag. You also have a 0-1
quantifier after the first capture group, and the OP doesn't seem to
want an empty table. You have an unnecessary escape of "<" for the end
table tag.

@OP: unfortunately, this approach relies on the site authors not
changing their code. We can further minimize hard coding by using the
pre-defined space character class, and case insensitivity. The /x
modifier let's your regex ignore space and easily insert comments.

preg_match(' ~
<table \s+ # open table tag

# attributes
border=[\'"]1[\'"] \s+
width=[\'"]315[\'"]>

(.*?) # table body

</table# end table tag
~sxi',
$source,
$match_array
);
>>Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!
Very good advice.
>>Regards,

Roger.


True enough, twas pretty slapdash, even for a usenet post ;-) For some
reason earlier my copy of php was choking on those left angle brackets
and I didn't want to spend the time figuring out why. Oddly enough
though I've just tried it with the angle brackets back in again and it
works fine now, go figure eh,! The surplus quantifier was a remnant from
an earlier attempt to step around the left bracket thing too.

Bloody regexes! I love them dearly but Zawinski had a point! :-)

Roger.
I struggled with regex for a long time, but now I love them as well.
Sorry if I came off as too pedantic, and yes, I use a quote from
Zawnski (maybe the same to which you referred) elsewhere. :-)

--
Curtis
Sep 16 '08 #7
Ecka wrote:
Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLEtag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
=============== =============== =============== =============== =============== ==============

<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
=============== =============== =============== =============== =============== ==============

Thanks
Eric

Hmmm, to me a regex seems a bit overkill here. There's a lot of
overhead with regex's.

How about something like:

$start = strpos($rawdata , '<TABLE BORDER="1" WIDTH="315">');
if ($start === false)
echo 'Start not found';
else {
$stop = strpos($text, '</TABLE>', $start);
if ($stop === false)
echo 'End not found';
else {
$text = substr($rawdata , $start + 31, $stop - $start - 31);
}

It's longer, but should have less overhead than a regex.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #8
Jerry Stuckle wrote:
Ecka wrote:
>Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that
I end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text
below and from the remaining HTML code, I'd like to extract the lines
starting with "<TABLE BORDER="1" WIDTH="315">" up to its closing
</TABLEtag. How do I do this using PHP? I tried using preg_match
and the like but my regex skills are pretty bad. Not too sure where
to start. Could someone please provide me with some pointers?
============== =============== =============== =============== =============== ===============

<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>

<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
============== =============== =============== =============== =============== ===============

Thanks
Eric


Hmmm, to me a regex seems a bit overkill here. There's a lot of
overhead with regex's.

How about something like:

$start = strpos($rawdata , '<TABLE BORDER="1" WIDTH="315">');
if ($start === false)
echo 'Start not found';
else {
$stop = strpos($text, '</TABLE>', $start);
if ($stop === false)
echo 'End not found';
else {
$text = substr($rawdata , $start + 31, $stop - $start - 31);
}

It's longer, but should have less overhead than a regex.
Jerry, I couldn't get your code to work, I had to make a few changes

$text = '';
$needle = '<TABLE BORDER="1" WIDTH="315">';
$start = strpos($rawdata , $needle);

if ($start === false)
echo 'Start not found';
else {
// first argument is $rawdata, not $text
$stop = strpos($rawdata , '</TABLE>', $start);

if ($stop === false)
echo 'End not found';

// removed extra { with no matching end }
else
$text = substr($rawdata , $start + strlen($needle) , $stop - $start
- strlen($needle) );
}

Changing to strlen makes it clearer than hard coding the string length
of the needle.

--
Curtis
Sep 16 '08 #9
Curtis wrote:
Jerry Stuckle wrote:
>Ecka wrote:
>>Hi everyone,

I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is
that I end up with a page that includes a lot of information that I
don't need. Using the PHP function strip_tags I've ended with the
text below and from the remaining HTML code, I'd like to extract the
lines starting with "<TABLE BORDER="1" WIDTH="315">" up to its
closing </TABLEtag. How do I do this using PHP? I tried using
preg_match and the like but my regex skills are pretty bad. Not too
sure where to start. Could someone please provide me with some
pointers?
============= =============== =============== =============== =============== =============== =

<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">som e text some text some text some text some text</td>
</tr>
</TABLE>

<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315" <-----
extract from here

<TR><TD>
some text some text some text some
text some text
</TD>
<TD ALIGN="right">
some text some text some text some
text some text
</TD></TR>
<TR><TD>
some text some text some text some
text some text
</TD>

<TD ALIGN="right">
some text some text some text some
text some text
</TD></TR>
<TR><TD>
some text some text some text some
text some text
</TD>
<TD ALIGN="right">
some text some text some text some
text some text
</TD></TR>
</TABLE<--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
============= =============== =============== =============== =============== =============== =

Thanks
Eric


Hmmm, to me a regex seems a bit overkill here. There's a lot of
overhead with regex's.

How about something like:

$start = strpos($rawdata , '<TABLE BORDER="1" WIDTH="315">');
if ($start === false)
echo 'Start not found';
else {
$stop = strpos($text, '</TABLE>', $start);
if ($stop === false)
echo 'End not found';
else {
$text = substr($rawdata , $start + 31, $stop - $start - 31);
}

It's longer, but should have less overhead than a regex.

Jerry, I couldn't get your code to work, I had to make a few changes

$text = '';
$needle = '<TABLE BORDER="1" WIDTH="315">';
$start = strpos($rawdata , $needle);

if ($start === false)
echo 'Start not found';
else {
// first argument is $rawdata, not $text
$stop = strpos($rawdata , '</TABLE>', $start);

if ($stop === false)
echo 'End not found';

// removed extra { with no matching end }
else
$text = substr($rawdata , $start + strlen($needle) , $stop - $start -
strlen($needle) );
}

Changing to strlen makes it clearer than hard coding the string length
of the needle.
You're right - I got the wrong parameter there - comes from changing
variable names in mid stream :-)

The reason I didn't use strlen was to try to cut down the overhead. I
just don't like using strlen with fixed length strings. Personal
preference, mostly.

In the real code I would have just added a comment indicating what the
31 was.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 17 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2057
by: Logical | last post by:
I wanted to do: include('page.htm?id=12&foo=bar'); But since I can't (and don't want to make another seperate HTTP request with include('http://...')); I was wondering if there's a function similar to extract(); that can handle a query string as input, so that I could: $id = 12; $foo = 'bar'; include('page.htm');
4
4565
by: David Chang | last post by:
I am trying to do some analysis on customer's locality, so I'd like to extract numeric part from address. Here is how the table looks like Table Member first_name last_name address1 address2 state zip ======= ======= =================== ===== === ===
2
1848
by: Kevin Morgan | last post by:
I'm trying to write a widget for Mac OSX Tiger. Here's the problem: The user enters a search term which is sent to a perl script on a remote server. This script returns a fully formatted HTML page. I only want part of that page to be displayed. How do I go about doing this? I'm a newbie when it comes to javascript..... Kev
4
7346
by: jrefactors | last post by:
How to extract data from html page? For example, if i want to get the information of weather (http://weather.yahoo.com/forecast/USCA1005.html) and put in my web page. Is it possible to do that? please advise. thanks!!
3
5995
by: Joe | last post by:
I'm trying to extract part of html code from a tag to a tag code begins with <span class="boldyellow"><B><U> and ends with TD><TD> <img src="http://whatever/some.gif"> </TD></TR></TABLE> I was thinking of using a regular expression however I having hard time getting the desired string. I use htmlSource = urllib.urlopen("http://address/")...
7
3123
by: A Causal | last post by:
I'm an experienced C programmer, but I have never worked with any sort of internet programming. I would like to write a program to search for certain character strings in a currently displayed web page, and then get the string that immediatly follows the one that I searched for. It seems like an easy thing to do, after all the stuff that I...
3
1496
by: Robot | last post by:
Dear all, I need to create a script which will extract the contents of 2 cells of an html that contains a specified number of cells.Then I need to put that contents in another cells of my own html page.How can i do that?Any samples, tutorials, advice?
7
15724
by: Ulysse | last post by:
Hello, I'm trying to extract the data from HTML table. Here is the part of the HTML source : """ <tr> <td class="tdn" valign="top"> <input name="x44553130" value="y" type="checkbox"></td> <td class="tdn" valign="top" width="30%">
9
9261
by: flit | last post by:
Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: " Return-Path: X-Original-To: Received: from
0
7854
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7783
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8296
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7880
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6539
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.