Current location: Hot Scripts Forums » Programming Languages » PHP » Do you know the idea of fetch data from Html by PHP and save it to database ?


Do you know the idea of fetch data from Html by PHP and save it to database ?

Reply
  #1 (permalink)  
Old 11-07-06, 08:25 PM
sharif_aly sharif_aly is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Do you know the idea of fetch data from Html by PHP and save it to database ?

Do you know the idea of fetch data from Html by PHP and save it to database ?
Reply With Quote
  #2 (permalink)  
Old 11-07-06, 09:04 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by sharif_aly
Do you know the idea of fetch data from Html by PHP and save it to database ?
Yes, I know that idea quite well. It's a great idea and I highly recommend it.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 11-07-06, 10:01 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
All these years, why haven't I thought of that?!
__________________
The toxic ZCE
Reply With Quote
  #4 (permalink)  
Old 11-08-06, 05:13 AM
sharif_aly sharif_aly is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
why you say that ??

what i really mean is there is a website i want fetch data from it by some how like yahoo movies and i want fetch information about a movie to add it somehow to mysql data base i just want to know the idea of fetching data so i can do it on any kind of website to get data like wikipedia or any other site .

Last edited by sharif_aly; 11-08-06 at 05:20 AM.
Reply With Quote
  #5 (permalink)  
Old 11-08-06, 11:31 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by Keith
All these years, why haven't I thought of that?!
It was just so bloody obvious, we missed it. And all this time I've been calling the sysadmin and asking him what was on the screen...
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 11-08-06 at 11:36 AM.
Reply With Quote
  #6 (permalink)  
Old 11-08-06, 11:34 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by sharif_aly
why you say that ??
We were just being funny. In theory, anyway. At least it should have been funny to anyone who didn't have their humor gland shot off in the war.


Quote:
Originally Posted by sharif_aly
what i really mean is there is a website i want fetch data from it by some how like yahoo movies and i want fetch information about a movie to add it somehow to mysql data base i just want to know the idea of fetching data so i can do it on any kind of website to get data like wikipedia or any other site .
You could use cURL to retrieve the data, then do some post-processing on the result and then stick it in the database. That's the way I've always done it. I'd recommend grabbing the entire raw page and storing that, then you can do the post-processing at your leisure without hammering the target site to death.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #7 (permalink)  
Old 11-08-06, 04:16 PM
sharif_aly sharif_aly is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
End User : can you make an example please.
Reply With Quote
  #8 (permalink)  
Old 11-08-06, 06:24 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by sharif_aly
End User : can you make an example please.
I thought I just did. (??) Or are you asking for some sample code?

This assumes you have an array of URLs in "$URL" and a table named "savedpages" with a column named "thepage".
PHP Code:

// make a mysql connection here, etc etc


start retrieving pages.....
foreach(
$URL as $myurl){

// get the page....
$ch curl_init();
curl_setopt($chCURLOPT_URL'http://www.example.com');
curl_setopt($chCURLOPT_HEADER1);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$data curl_exec();  // page data is in $data
curl_close($ch);

// do some processing of the data here if you want...
$data my_cool_function($data);

// Then insert the information into the table "savedpages"
$query "INSERT INTO savedpages (thepage) VALUES ('$data')";  

$result mysql_query($query) or die(mysql_error());

// end foreach 
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by Nico; 11-08-06 at 06:42 PM.
Reply With Quote
  #9 (permalink)  
Old 11-09-06, 07:14 AM
sharif_aly sharif_aly is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you for the code

but why this way why not HTML parser ?
Reply With Quote
  #10 (permalink)  
Old 11-09-06, 07:56 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
my_cool_function() in the above example would be where you'd handle the parsing.
__________________
The toxic ZCE
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How-to: Parser HTML from a webpage and save to text file gx10vn PHP 6 06-09-06 05:40 PM
PHP and Database HTML store NoMercy PHP 5 04-22-06 03:24 PM
Saving php generated file as html file GS300 PHP 0 12-29-04 03:34 AM
saving data with PHP form sXenoGJ PHP 4 04-30-04 11:25 PM
Need Help how to save file in server in PHP JTran PHP 1 04-21-04 07:29 AM


All times are GMT -5. The time now is 05:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.