angela_b Posted January 19, 2010 Share Posted January 19, 2010 I am trying to pull about ten titles and meta descriptions from different urls through a function. I am able to get them to echo and show on a webpage, however what I would like to do is take all that data and insert it into a database. If anyone could tell me how to get each one to post to a database that would be great. Thanks. Below is what I have, but it is not posting all the data to the database. require '/home2/file.php'; error_reporting(0); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); function meta($type,$url,$name) { if( ereg("^((http|https|ftp)://)?(((www\.)?[^ ]+\.[com|org|net|edu|gov|us])|([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+))([^ ]+)?$", $url) == true) { $chopped = parse_url($url); $host = $chopped[host]; $page = $url; $contents = implode(' ', file($page)); if($contents) { if(eregi('<title[^>]*>([^<]*)</title[^>]*>', $contents, $regs)) { $title = trim(ereg_replace('[[:space:]]+', ' ', $regs[1])); $metaTags = get_meta_tags($url); $description = $metaTags['description']; $sql="INSERT INTO resources ('type','url','name','title','description') VALUES('$type','$url','$name','$title','$description')"; $result=mysql_query($sql); } } } } { meta("formwebsites", "http://entrepreneurs.about.com", "About.com"); meta("formwebsites", "http://www.allbusiness.com/business-planning-structures/starting-a-business/3470974-1.html", "AllBusiness.com"); meta("formwebsites", "http://www.bbb.org", "Better Business Bureau"); meta("formwebsites", "http://www.dartmouth.edu/~tto/", "Darthmouth College"); meta("formwebsites", "http://www.entrepreneur.com/", "Entrepreneur.com"); meta("formwebsites", "http://www.hbs.edu/entrepreneurship/", "Harvard Business School"); meta("formwebsites", "http://www.sba.gov/services/training/onlinecourses/index.html", "SBA-SBTN Online Courses"); meta("formwebsites", "http://www.sba.gov/", "Small Business Administration"); meta("formwebsites", "http://ecorner.stanford.edu/", "Stanford"); meta("formwebsites", "http://www.techcrunch.com/", "TechCrunch"); meta("formwebsites", "http://venturehacks.com/", "Venture Hacks"); meta("formwebsites", "http://venturebeat.com/", "Venture Beat"); } Link to comment https://forums.phpfreaks.com/topic/189059-function-to-pull-meta-descriptions-from-urls-and-post-to-database/ Share on other sites More sharing options...
angela_b Posted January 20, 2010 Author Share Posted January 20, 2010 anyone?? Thanks again for looking! Link to comment https://forums.phpfreaks.com/topic/189059-function-to-pull-meta-descriptions-from-urls-and-post-to-database/#findComment-998363 Share on other sites More sharing options...
fenway Posted January 20, 2010 Share Posted January 20, 2010 I don't understand teh question. Link to comment https://forums.phpfreaks.com/topic/189059-function-to-pull-meta-descriptions-from-urls-and-post-to-database/#findComment-998452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.