Jump to content

Function to pull meta descriptions from urls and post to database.


angela_b

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.