anon Posted December 25, 2007 Share Posted December 25, 2007 This is a basic snippet for getting data from a web page (right?) $text = file_get_contents($url); file_put_contents($save_location, $text); Could i make $url a function? As in $url= "this will change as I go through a list of URL's in a database, then apply the file_get_contents?" (i'm a fat n00b) Then obviously $save_location would be the database I want to save it to? Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/ Share on other sites More sharing options...
wolfrat Posted December 25, 2007 Share Posted December 25, 2007 What exactly are you trying to do here? By making $url a function, do you mean, get functions from external pages and load them/save them into the php page? Or do you just want to make a function that makes it easier for you to download pages? (i.e. having something like download($page) Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/#findComment-423047 Share on other sites More sharing options...
Stooney Posted December 25, 2007 Share Posted December 25, 2007 Maybe something like this: <?php //assuming you're connected to db $getlist=mysql_query("SELECT url FROM url_table"); while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); file_put_contents($save_location, $row[0]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/#findComment-423052 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 so at the top i would mysql_connect then put the code. But i would have to specify "$save_location" Would this just be insert into database + table of choice? Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/#findComment-423458 Share on other sites More sharing options...
anon Posted December 26, 2007 Author Share Posted December 26, 2007 <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'url'; mysql_select_db($dbname); //would i still need to connect to table? $getlist=mysql_query("SELECT url FROM url_table"); while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); file_put_contents($save_location, $row[0]); } ?> Would this work Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/#findComment-423506 Share on other sites More sharing options...
Stooney Posted December 27, 2007 Share Posted December 27, 2007 This should work for you. I don't know how you go about naming the file you store the data in so if you need help with that just explain how you want it to work. <?php define ('DB_USER', 'username'); define ('DB_PASSWORD', 'password'); define ('DB_HOST', 'host'); define ('DB_NAME', 'database name'); $dbc=@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect: ' . mysql_error()); @mysql_select_db(DB_NAME) OR die ('Could not select database: ' . mysql_error()); $getlist=mysql_query("SELECT url FROM url_table"); while($row=mysql_fetch_array($getlist)){ $save_location="filename.txt"; //change this to what you need it to be $text = file_get_contents($row[0]); file_put_contents($save_location, $text); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83168-help-tying-code-together/#findComment-424037 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.