Jump to content

Extracting Keywords Problem


soma56

Recommended Posts

I found this script and have been playing with it for the last few hours to spit out keywords line by line.

 

<?php

include 'parse.php';
$Parse = new ParseSite("http://mysite.com");
echo "<pre>";
var_dump(
$Parse->get_keywords(),
);
echo "</pre>";
?>

 

<?php
class ParseSite{

var $DataFromSite = '';

function __construct($url){
$this->url = $url;
$this->DataFromSite = $this->grab_page();
}

private function grab_page(){
$this->CurlOP = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => false, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "LWS V1.0", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl
CURLOPT_SSL_VERIFYPEER => false, //
);
$this->ch = curl_init($this->url);
curl_setopt_array($this->ch,$this->CurlOP);
$this->Data = curl_exec($this->ch);
curl_close($this->ch);
return $this->Data;

// retrieve keywords
function get_keywords(){
$h1tags = preg_match('/(<meta name="keywords" content="(.*)" \/>)/i',$this->DataFromSite,$patterns);
$res = array();
array_push($res,$patterns[2]);
return $res;
}

 

I'm trying to retrieve keywords doing something like this:

 

// retrieve keywords
function get_keywords(){
$h1tags = preg_match('/(<meta name="keywords" content="(.*)" \/>)/i',$this->DataFromSite,$patterns);
$res = array();
array_push($res,$patterns[2]);
$data = explode(",", "$res"); 
foreach ($data as $value) 
if (empty($value)){
	var_dump($value);
} else { 
echo $value . "<br />" . PHP_EOL;
flush();
    ob_flush();
    usleep(500000);
}
}

 

Am I on the right track?

Link to comment
https://forums.phpfreaks.com/topic/204801-extracting-keywords-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.