Log in

View Full Version : copy a table



byronghislain
08-17-2007, 12:59 AM
I will like to copy a table being from another site to put it on my page.
Thus if the table of the external site is modified, my table changes alone while being based on the other.

Is this possible?


ps: excuse me for my english but i speak french

djr33
08-17-2007, 05:50 PM
It is possible, using PHP.

<?php include('http://the.com/the/page.htm'); ?>

That would include the whole page into your page where that code is. I would suggest having just the table in a document.

For example:

table.txt:
<table>...my data here...</table>

On both page 1 and page 2:
<?php include('table.txt'); ?>

It would be a lot more work to first extract the table and then place it into a new page. If you need this, we can probably help, though.
You could use file_get_contents('the.txt') and then split it using string functions, like substr, strpos, etc.

byronghislain
08-17-2007, 06:15 PM
in fact the problem is that I is not the possibility of modifying the source page in which the table is that I have need.
Thus it will be necessary that I make a which page either duplicates the table, or that information of table source sent directly in my base of data so that don&#233;es replace themselves in the new table.

(if that is possible with another language that the php, that will also go)

djr33
08-17-2007, 07:40 PM
No reason to use another language. you need a serverside language, like PHP, and there's nothing wrong with using PHP.

It's just hard.

<?php
$f = file_get_contents('http://whatever.com/stuff/page.htm');
echo substr($f,strpos($f,'<table>'),strpos($f,'</table>',strpos($f,'<table>'))-strpos($f,'<table>'));
?>

That will find the first instance of the characters "<table>" in the source code of that page, and continue until the first instance after of "</table>".

This isn't very reliable, though, because you must find the RIGHT instance of the table and the right close tag. I suggest looking at those two functions, strpos and substr, and finding a way to use them to find the right table on the page.
If you happen to know it says "options:" and the table is after that, for example, you could use that as a marker, and make sure that it only finds results after "options:".

byronghislain
08-17-2007, 08:59 PM
Thus that will enable me to find the beacon table
do I have compri well?

here there is plusior table on the page, and that which I have need, is not the first.

Thus thanks must then to the name to give to the table, I have easy not?

djr33
08-17-2007, 09:14 PM
You must find a way to distinguish the table.
Find a set of characters in the source code that will always be there and is as close as possible to the table you want.
You could link to the page and I could check.

byronghislain
08-17-2007, 09:18 PM
apparently it is identical table with each time a beacon <br> enters

but it is a table has two lines.

Thus perhaps that I can use the first line containing the title of the table in order to copy the second line which contains the essential contents

djr33
08-17-2007, 09:22 PM
Sure.
You need a CLEAR marker that will never change, and you can get any data you want in relation to that.

The computer doesn't see tables. It just sees characters. So you can tell it to look for "t" before "a" before "b" before "l" before "e", etc., but it won't be able to guess what you want.

You will need a clear marker before and after (after can be less clear as long as it is the first instance after the start), or a position and length, etc.

byronghislain
08-17-2007, 09:29 PM
thus I can say to him to take into account of beacon TD being after such word text (as the title) until the end of this beacon.

Is this well that?

Twey
08-17-2007, 09:59 PM
The computer doesn't see tables. It just sees characters.Unless you use a DOM parser. Then it sees elements.
<?php include('http://the.com/the/page.htm'); ?>Now this is a very bad idea. That HTML page will be included -- and executed as PHP code. It effectively gives the owner of the remote server access to your server with the access rights of the server process -- which is enough to much up your files and probably steal a database password or two, at least.

byronghislain
08-17-2007, 10:03 PM
You have another idea which will make it possible to take only one table of the page without forgetting that table source will make it possible my table to remain up to date

but I does not include/understand why the preceding idea is bad but good I do not know anything large thing in php

Twey
08-17-2007, 10:13 PM
djr33's other idea using file_get_contents() is sound.

byronghislain
08-17-2007, 10:14 PM
do you have another idea?
I will test all the ideas suggested

djr33
08-17-2007, 10:46 PM
That's how I'd do it. I don't see a reason to use anything else.


Now this is a very bad idea. That HTML page will be included -- and executed as PHP code. It effectively gives the owner of the remote server access to your server with the access rights of the server process -- which is enough to much up your files and probably steal a database password or two, at least.No... for security, pages on other servers are executed as plain text, passed directly to the output buffer. No?
It certainly can't grab PHP files off the server. I suppose they could embed plain text php code in the page, but I don't think that would be executed.

byronghislain
08-17-2007, 11:13 PM
with what had begun you to explain to me Ca will be possible?

if I says that it must take the beacon <td> which is right after the title of the table and post it until the end of the </td>

it is possible that?

djr33
08-18-2007, 12:17 AM
You could post a link, as I said before, and we could give you an example.


Look at this:

212141423232141422

Let's say you wanted to find the bold "1".

Well, just finding one would return the second character.

It's between two "4"s. That's helpful.

substr($string,strpos($string,'4'),strpos($string,'4',strpos($string,'4'))-strpos($string,'4'));
That would find the string between the first four, and the next four after it.

But... there's another 4, earlier in the page. What now?

Well, let's make the whole thing be AFTER the pattern "321":
$string = substr($string,strpos($string,'321');
//then use the line above


So, basically, the point is that you would need to narrow it down, and be sure that what you search for won't change.

If you were to grab an email from a page in this format:
<b>Name</b>: Some One
<b>Email</b>: some@one.com
<b>Site</b>: some.com

You would know to look for the word "Email" in the text. But even better, the string "<b>Email</b>:", because that won't be repeated anywhere else in the text (at least the odds are for it).

Then get the text after it, but only up to the next line break.

That's the basic idea, and we can't answer any more questions without knowing the exact pattern being searched.

byronghislain
08-18-2007, 12:21 AM
I sent a bond by private message to you

djr33
08-18-2007, 12:36 AM
Ok, I got the message, and replied with the code there.

For anyone else to reference, here's some code that should work, though it is specific to the page in question:


<?php

function get_table($page,$b) {
$f = file_get_contents($page);
$st = strpos($f,'<table',strpos($f,'<b>'.$b.'</b>'));
$fn = strpos($f,'</table>',strpos($f,'<table',strpos($f,'<b>'.$b.'</b>')))-strpos($f,'<table',strpos($f,'<b>'.$b.'</b>'));
return substr($f,strpos($f,'<table',$st,$fn);
}

echo get_table('http://the.com/page.htm','D+');

?>


This solution will work for most cases, but sometimes there might be something weird that happens, like a table in the middle of the table, and it gets confusing.

byronghislain
08-18-2007, 12:38 AM
An enormous mercy,

I test that and I keeps you informed

thank you thank you

byronghislain
08-18-2007, 12:41 AM
And the link which is in echo, it is my URL of my site which I must put with the bond of the page or the new table or the page of the old table will be?

Twey
08-18-2007, 07:41 AM
No... for security, pages on other servers are executed as plain text, passed directly to the output buffer. No?You'd think so, wouldn't you? I got bitten by this one.

djr33
08-18-2007, 10:05 AM
The URL in the echo statement is the page you are looking for the table.

It will get the html from that page and search it for the table.



Twey, that's really stupid. Perhaps this is the root of your dislike for the language? :p

tech_support
08-18-2007, 10:34 AM
You'd think so, wouldn't you? I got bitten by this one.
You can't include remote files with PHP5. It's disabled by default.

I've even tried it with the GoDaddy servers...
Unless you're hosted with erm... STUPID PEOPLE?

djr33
08-18-2007, 10:37 AM
But you should be able to. It simply shouldn't be a security risk. Perhaps they'll fix with PHP6....

tech_support
08-18-2007, 10:48 AM
Warning: include() [function.include]: URL file-access is disabled in the server configuration in G:\apache\htdocs\home\peter\public_html\remoteinclusion.php on line 1

Warning: include(http://thebrbforums.com/) [function.include]: failed to open stream: no suitable wrapper could be found in G:\apache\htdocs\home\peter\public_html\remoteinclusion.php on line 1

Warning: include() [function.include]: Failed opening 'http://thebrbforums.com/' for inclusion (include_path='.;C:\php5\pear') in G:\apache\htdocs\home\peter\public_html\remoteinclusion.php on line 1

byronghislain
08-18-2007, 02:17 PM
veiled I have to test script php but when I open the page with my exploring it posts me only that

'.$b.'')); $fn = strpos($f,'',strpos($f,''.$b.'')))-strpos($f,''.$b.'')); return substr($f,strpos($f,'

djr33
08-18-2007, 02:36 PM
In order to use PHP code on the page, you must place it within <?php ..... ?> tags, have PHP installed/enabled on your server, and the page must end with the .php extension, not .htm.
I'm guessing that the last thing is the problem. Rename your page [yourname].php

Twey
08-18-2007, 02:40 PM
Perhaps this is the root of your dislike for the language?No, not really. It certainly doesn't curry it any favour, but the root of my dislike for the language is its inane inflexibility -- like passing "functions" by passing their name as a string, and defining all functions superglobally to make this possible.
Warning: include() [function.include]: URL file-access is disabled in the server configuration in G:\apache\htdocs\home\peter\public_html\remoteinclusion.php on line 1That means you have url_fopen disabled entirely, not just for includes. This will prevent you doing fopen() or get_file_contents() on remote resources as well. It's about 50:50 whether a given server will have this enabled or not, in my experience.
veiled I have to test script php but when I open the page with my exploring it posts me only that

'.$b.'')); $fn = strpos($f,'',strpos($f,''.$b.'')))-strpos($f,''.$b.'')); return substr($f,strpos($f,'The PHP isn't being parsed.

byronghislain
08-18-2007, 08:21 PM
my waiter accepts the php well. The name of the file is correct (test.php).

do you have an idea on the failure of this script at home?

I have to test on several waiters and it always posts an error
http://membres.lycos.fr/powersat2/
http://powersat.alwaysdata.net

even with the various waiters, script does not post what it would owe

djr33
08-18-2007, 10:52 PM
Here's the code, fixed a bit:

<?php

function get_table($page,$b) {
$f = file_get_contents($page);
$st = strpos($f,'<table',strpos($f,'<b>'.$b.'</b>'));
$fn = strpos($f,'</table>',$st)-$st;
return substr($f,$st,$fn);
}

echo get_table('http://the.com/page.htm','D+');

?>

byronghislain
08-18-2007, 11:41 PM
now it posts a table but it does not post the good table.

it posts just the petittableau description gold which it will have to post Digital+ table

http://powersat.alwaysdata.net

djr33
08-18-2007, 11:49 PM
Try adding more data to what you're searching for.
Right now it finds the first complete table after <b>$term</b>, so look for something more specific in the source code. Trial and error should work.

byronghislain
08-18-2007, 11:56 PM
veiled I copied here the script of the table which I have need.

I notice that all the tables are identical. On the other hand, I would like to know if it will be possible to take only the second line bus
that will allow to ask to take starting from the beacon <td… by specifying that the beacon is after the word D+ what will make it possible to take the good line.

The problem is that I will not be to transform that into script




<TABLE BORDER="0" CELLSPACING="0" WIDTH="70&#37;" BGCOLOR="#F0F0F0" cellpadding="1">
<TR><TD>
<TABLE BORDER="0" CELLSPACING="0" WIDTH="100%" BGCOLOR="#F0F0F0">
<TR>
<TD COLSPAN="2" align="center"><a href="http://www.rdi-cards.com/pic.php?i=digital_plus_45.jpg" target="_blank"><img src="/sigle/digital_plus_45.jpg" border="0"></a>&nbsp;<br><font face="MS Sans serif,Arial" size="3"><b>***D+***</b></font><br><font face="MS Sans serif,Arial" size="2" color="#888888">ID </font><font face="MS Sans serif,Arial" size="2" color="#888888">41 01</font></TD>
</TR>

<TR>

***<TD *** align="center" COLSPAN="2" bgcolor="#E0E0E0">
<TABLE BORDER="0" CELLSPACING="0" cellpading="0" WIDTH="100%" BGCOLOR="#FAFAFA">
<TR bgcolor="#F5F5F5">
<td width=16% align=center><font face="Verdana, Arial" size="1" color=black>IDEEA key 86</font></td>
<td align="center"><font face="Verdana, Arial" size="2" color=blue>E2 09 81 A6 4F 35 D9 B9 3F CB 31 0A 02 D5 E9 D7</font></td>
</TR>

<TR bgcolor="#F5F5F5">
<td width=16% align=center><font face="Verdana, Arial" size="1" color=black>IDEEA key </font></td>

<td align="center"><font face="Verdana, Arial" size="2" color=blue>226 009 129 166 079 053 217 185 063 203 049 010 002 213 233 215 </font></td>
</TR>

<TR bgcolor="#F5F5F5">
<td width=16% align=center><font face="Verdana, Arial" size="1" color=black>IDEEA key 96</font></td>
<td align="center"><font face="Verdana, Arial" size="2" color=black>40 3B 30 A3 2B 96 60 93 2E 7F A9 05 33 DE 6D 5D</font></td>
</TR>

<TR bgcolor="#F5F5F5">
<td width=16% align=center><font face="Verdana, Arial" size="1" color=black>IDEEA key </font></td>
<td align="center"><font face="Verdana, Arial" size="2" color=black>064 059 048 163 043 150 096 147 046 127 169 005 051 222 109 093</font></td>
</TR>


<TR bgcolor="#F5F5F5">
<td width=16% align=center><font face="Verdana, Arial" size="1" color=black>RSA key<br></font><font face="Verdana, Arial" size="1" color="#C0C0C0">(128 chars)</font></td>

<td align="center"><font face="Verdana, Arial" size="2" color="green">D91FB482F54C4535621D845F7EC4AB4DC9309DED26B54030848EB63968977529<br>FE8FF18613276171E57BDA8A47AC993703CCE2A1CB071998ECCB327EF63CCEA7</font></td>
</TR>
</TABLE>
</td>
</TR>
</TABLE>



I have semi *** who surround the beacon that I speak for better to find them, it is the only thing which differentiates the different table

It's possible??

djr33
08-19-2007, 12:29 AM
The script I used searches for <b>***</b>, as above.
That's really all I can suggest.

The framework is there. You should be able to learn the PHP and do the rest yourself. At this point, all you need to do is figure out how to identify each section of code.

byronghislain
08-23-2007, 12:05 PM
veiled I made full with test but I never manage to post the table necessary.

I believe that I will make better give up this site.

thank you to you for the explication.et your assistance has

I just succeeded in once posting a line with a indication and also posting all the title of the page to the top but not the table

http://powersat.alwaysdata.net/test.php

tech_support
08-24-2007, 07:57 AM
That means you have url_fopen disabled entirely, not just for includes. This will prevent you doing fopen() or get_file_contents() on remote resources as well. It's about 50:50 whether a given server will have this enabled or not, in my experience.
Hmm... Must of been a PHP Default.

byronghislain
07-18-2008, 01:16 PM
I would just copy the calendar because I find it well done and I do not have the competence to do it by myself

I have the table Site
http://www.poker-actu.fr/programme/tv/poker/

With the list of channels.

Because I am a site on poker and it would be nice to have this programme schedule

Thank you