p17blo Posted February 6, 2007 Share Posted February 6, 2007 Hi, I am trying to find a way with PHP to read some data from a website (the url is always static and the return is always 'similar' to ABC1.2.3=987&). I basically need to read the portion between the = and the &, divide this number by 10 and enter this into the next available row in a specific mysql db table with a date and time stamp. Would really appreciate some guidance. Thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/ Share on other sites More sharing options...
.josh Posted February 6, 2007 Share Posted February 6, 2007 is this an external website? is this string part of the actual contents of the webpage? Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/#findComment-178665 Share on other sites More sharing options...
p17blo Posted February 6, 2007 Author Share Posted February 6, 2007 is this an external website? is this string part of the actual contents of the webpage? It is an external website but the return is simply an unformatted page exactly as detailed. (no html presence at all) I can already send a $out = readfile to the page and display a similar result. What I can't do is manipulate and stuff it into a DB. Paul Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/#findComment-178667 Share on other sites More sharing options...
.josh Posted February 6, 2007 Share Posted February 6, 2007 so are you having issues with the regex or the inserting it into the db? or both? As far as the regex is concerned, is the data always going to be in between =...&? is there more than one possible match to consider? As far as the inserting into the db, do you know how to connect to your db and display info? That is, are you looking for help with an actual query string, or do you know nothing about the whole db thing at all? Do you even have a db setup? In other words, you need to be very specific about your situation. Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/#findComment-178674 Share on other sites More sharing options...
p17blo Posted February 6, 2007 Author Share Posted February 6, 2007 OK, Yes I need help with the connection string. I do not currently have the DB set up but I know how to create the DB and the required table. Apologies for the ignorance but I don't know how to connect my MYSQL table to my PHP page for input or output. I do currently have many other MYSQL dbs setup and running from this server. The table I will create will have 2 fields. A time/date stamp plus a numeric field to store this output. The data will ALWAYS be between the =...& but may vary in length. It will only ever have one match on one single line returned. Please let me know what other information I can supply to assist. Thanks for your help Paul so are you having issues with the regex or the inserting it into the db? or both? As far as the regex is concerned, is the data always going to be in between =...&? is there more than one possible match to consider? As far as the inserting into the db, do you know how to connect to your db and display info? That is, are you looking for help with an actual query string, or do you know nothing about the whole db thing at all? Do you even have a db setup? In other words, you need to be very specific about your situation. Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/#findComment-178689 Share on other sites More sharing options...
.josh Posted February 7, 2007 Share Posted February 7, 2007 <?php // connect to database $conn = mysql_connect('localhost','dbusername','dbpassword') or die(mysql_error()); $db = mysql_select_db('dbname',$conn) or die(mysql_error()); // example string $blah = "blah=something&blahblah"; preg_match("/=(.*)&/", $blah, $info); // insert into database $sql = "insert into table (column) values ('{$info[1]}')"; $result = mysql_query($sql, $conn) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/37373-how-to-read-data-from-a-web-page-and-enter-into-mysql/#findComment-178702 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.