php - 网站关键词、无限加载、OOP

标签 php mysql database oop

我正在从不同的网站创建关键字,并将它们保存在 bd 中。

在 $webhtml 中,我有一个使用 DOM 下载的网站。问题是,当您启动提取器时,会无限加载。并且永远不会在数据库中保存任何内容。

有错误的代码如下:

if (empty($keywords)){
$ekeywords = new KeyPer;
$keywords = $ekeywords->Keys($webhtml);
}

我用一个函数存储了 $keywords: saveweb($url, $description, $keywords);

我使用下一个包括:

include("Extkeys.php");

“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; 
} 
}
?>

如何避免代码的无限负载并使其正常运行?

最诚挚的问候!

最佳答案

在您的代码中,您正在用空格替换空格,

while (strchr($webhtml," ")) { 
    $webhtml = str_replace(" ", " ",$webhtml); 
} 

应该是这样的

while (strchr($webhtml," ")) { 
    $webhtml = str_replace(" ", "",$webhtml); 
} 

关于php - 网站关键词、无限加载、OOP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13662261/

相关文章:

php - 使用提交按钮通过 PHP 将条目插入 MySQL 数据库?

sql-server - 如何跨多个表强制执行 CHECK 约束

PHP 类构造函数将 mysql 行作为对象返回

php - Symfony 2 在两个域上登录

Mysql查询速度很慢 如何优化查询?

php - 如何正确比较 strtotime 中的两个值

mysql - 在域对象约束中指定grails浮点精度,如何?

java - 检查Java中数据库表中是否存在单词

ruby-on-rails - Ruby on Rails : Uniqueness of elements in drop down menu

php - 如何在eclipse中生成getter和setter (php)