I’m creating keywords from different websites, and save them in a bd.
In $webhtml, I have a websites downloaded with DOM. The problem is that when you start the extractor, is loaded infinitely. And never saves anything in the database.
The code that has the error is the follows:
if (empty($keywords)){
$ekeywords = new KeyPer;
$keywords = $ekeywords->Keys($webhtml);
}
I stored $keywords with a function:
saveweb($url, $description, $keywords);
And i use the next include:
include("Extkeys.php");
The code of “Extkeys”:
<?php
class Extkeys {
function Keys($webhtml) {
$webhtml = $this->clean($webhtml);
$blacklist='de,la,los,las,el,ella,nosotros,yo,tu,el,te,mi,del,ellos';
$sticklist='test';
$minlength = 3;
$count = 17;
$webhtml = preg_replace('/[\.;:|\'|\"|\`|\,|\(|\)|\-]/', ' ', $webhtml);
$webhtml = preg_replace('/¡/', '', $webhtml);
$webhtml = preg_replace('/¿/', '', $webhtml);
$keysArray = explode(" ", $webhtml);
$keysArray = array_count_values(array_map('strtolower', $keysArray));
$blackArray = explode(",", $blacklist);
foreach($blackArray as $blackWord){
if(isset($keysArray[trim($blackWord)]))
unset($keysArray[trim($blackWord)]);
}
arsort($keysArray);
$i = 1;
$keywords = "";
foreach($keysArray as $word => $instances){
if($i > $count) break;
if(istrlen(trim($word)) >= $minlength && is_string($word)) {
$keywords .= $word . ", ";
$i++;
}
}
$keywords = rtrim($keywords, ", ");
return $keywords=$sticklist.''.$keywords;
}
function clean($webhtml) {
$regex = '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)(\\.[A-Za-z0-9-]+)*)/iex';
$desc = preg_replace($regex, '', $webhtml);
$webhtml = preg_replace( "''si", '', $webhtml );
$webhtml = preg_replace( '/]*>([^<]+)<\/a>/is', '\2 (\1)', $webhtml );
$webhtml = preg_replace( '//', '', $webhtml );
$webhtml = preg_replace( '/{.+?}/', '', $webhtml );
$webhtml = preg_replace( '/ /', ' ', $webhtml );
$webhtml = preg_replace( '/&/', ' ', $webhtml );
$webhtml = preg_replace( '/"/', ' ', $webhtml );
$webhtml = strip_tags( $webhtml );
$webhtml = htmlspecialchars($webhtml);
$webhtml = str_replace(array("\r\n", "\r", "\n", "\t"), " ", $webhtml);
while (strchr($webhtml," ")) {
$webhtml = str_replace(" ", " ",$webhtml);
}
for ($cnt = 1;
$cnt < strlen($webhtml)-1; $cnt++) {
if (($webhtml{$cnt} == '.') || ($webhtml{$cnt} == ',')) {
if ($webhtml{$cnt+1} != ' ') {
$webhtml = substr_replace($webhtml, ' ', $cnt + 1, 0);
}
}
}
return $webhtml;
}
}
?>
How I can avoid the infinite load of code, and make it functional?
Best regards!
In your code, you are replacing space with space,
it should be like