Hi all
I was wondering if there was a way of getting all the data in

item[0]

into a mysql db.
This is for my website, and i don't want to visit all the site to get the content.

The example:

$load = new DOMDocument;
$load->loadHTMLFile('http://www.website/index.php');

echo $load->getElementsByTagName('table')->item(0)->textContent;

The above code displays all the date between the table, i just need it to be saved to a mysql db.

Thanks All

Recommended Answers

All 11 Replies

Instead of echo, assign the value to a variable and insert it to the table.

Hi Naveen

thanks for helping me again, Is it possible to load all the data i get in a array form?

the value

$dom = new DomDocument();
$dom->loadHTMLFile("http://www.website.com");
$titles = $dom->getElementsByTagName("table");
foreach($titles as $node) {
   $value = $node->textContent;
echo  $value;
}

This displays all the values at onces.

Contract Buy Price Sell Price Last Price Change
JUN08 4036.00 4040.00 4040.00 -20.00
JUL08 4090.00 4096.00 4090.00 25.00
SEP08 4180.00 4205.00 4185.00 -20.00
JUN08 4852.00 4855.00 4855.00 -20.00

I would like to get it in separate values.

Thanks Again

What do you mean by separate values ? You mean, its displaying 1 row at a time and you want it to be separated ?

Hi Naveen.

Sorry went to the doctor(malaria), sucks. Yes if i run the php script as above it puts all the html data in the variable. I only need the data like this example:

Contract Buy Price Sell Price Last Price Change
JUN08 4036.00 4040.00 4040.00 -20.00
JUL08 4090.00 4096.00 4090.00 25.00
SEP08 4180.00 4205.00 4185.00 -20.00
JUN08 4852.00 4855.00 4855.00 -20.00

what will be the best way to get only the data like the example?

Thanks

Sorry to hear bout malaria ! Get well soon :) And, I don't see any difference between the first example and this one.. Umm.. But if you want the records separately, why don't you add each record to an array and print it as you want it !

Hi Naveen

Can you please help me with a sample array code query,or the way you would do it. Would appreciates it allot.

Thanks again

$dom = new DomDocument();
$value = array();
$dom->loadHTMLFile("http://www.website.com");
$titles = $dom->getElementsByTagName("table");
foreach($titles as $node) {
   $value[] = $node->textContent;
}
//$value[0] will have the first record, $value[1] will have the 2nd record and so on..

Hi Naveen

Thanks for all your help so far, the following code works and put data in $value[0], I would like to know how to put each and every value captured in $value into a variable?

$dom = new DomDocument();
$value = array();
$dom->loadHTMLFile("http://www.website.com");
$titles = $dom->getElementsByTagName("table");
foreach($titles as $node) {
   $value[] = $node->textContent;
}

The code gives me data like :

ContractBuy PriceSell PriceLast PriceChange SOYA JUN08 4043.00 4060.00 4043.00 -17.00 SOYA JUL08 4100.00 4117.00 4104.00 -11.00 SOYA SEP08 4190.00 4210.00 4185.00 -20.00 SUNS JUN08 4850.00 4859.00 4850.00 -25.00 SUNS JUL08 4921.00 4930.00 4922.00 -25.00 SUNS SEP08 5052.00 5063.00 5055.00 -20.00 SUNS DEC08 5241.00 5251.00 5242.00 -11.00 SUNS MAR09 4901.00 4920.00 4935.00 +.00 (all in $value[0])

If i where able to separate the code i could enter all the data into the mysql db.

Sorry for all the dumb questions, and thanks for all your help.

i appreciate all your help.

Umm.. You mean, you want to assign SOYA, JUN08, 4043.00 , 4060.00 etc in a separate variable ? Well, You have to change how textcontent returns the value. You should rather format it something like this.
array[1] =>
array("contractbuy") = "SOYA",
array("pricesell") = "JUN08",
... and so on..

You need to use multi-dimensional array in textContent..

Hi Naveen

Hope you are well today, Yes i would like to assign the values in $value[0] to a array, but it must be done automatically because the content of $value[0] changes every day, Don't know much about array's yet.

Is it possible to get the array's automatically?

Thanks allot

Hi Naveen

I don't understand array's at all, don't you think i'll be able to work with regular expressions in php. Search for specific data and display it.

Thanks

Cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.