该函数似乎是分析html标签的,但里面各个tag对应几个值到底何用?
看了半天没看明白,求高人指点。
//获得PR值
function getpr($arraycell, $searchaborative, $replaceaborative) {
$htmltags = array(
array('title', 5),
array('a', -1),
array('iframe', -2),
array('p', 1),
array('li', -1),
array('input', -0.1),
array('select', -3),
array('form', -0.1)
); if(strlen($arraycell['text']) > 10) {
if(strlen($arraycell['text']) > 200) {
$arraycell['pr'] += 2;
} foreach($htmltags as $tagsvalue) {
$temp = array();
preg_match_all("/\<$tagsvalue[0][^\>]*?\>/is", $arraycell['code'], $temp, PREG_SET_ORDER);
$tagsnum = count($temp); $temp = array();
if($tagsvalue[0] == 'title' && $tagsnum > 0) {
$arraycell['title'] = 'title';
} elseif($tagsvalue[0] == 'a' && $tagsnum > 0) {
preg_match_all("/\<a[^\>]*?\>(.*?)\<\/a>/is", $arraycell['code'], $temp);
$temp[2] = preg_replace("/[\n\r\s]*?/is", '', preg_replace ($searchaborative, $replaceaborative, implode('', $temp[1])));
$ahretnum = strlen($temp[2]) / strlen($arraycell['text']);
$tagsnum *= $ahretnum * 10;
} $arraycell['pr'] += $tagsnum * $tagsvalue[1];
}
} else {
$arraycell['pr'] -= 10;
} if($arraycell['pr'] >= 0) {
$g1 = preg_replace("/\<(p|br)[^\>]*?\>/si", "\n\n###p br explode###\n\n", $arraycell['code']);
$arrayg1 = explode("\n\n###p br explode###\n\n", $g1); preg_match_all("/\n\n###p br explode###\n\n/is", $g1, $g4, PREG_SET_ORDER); if(count($g4) > 2) {
$g3 = 0;
foreach($arrayg1 as $value) {
$g2 = preg_replace("/[\n\r\s]*?/is", "", preg_replace ($searchaborative, $replaceaborative, $value)); if($g2 != '') {
$g2num = strlen($g2);
if($g2num <= 25) {
$g3--;
} elseif($g2num > 70 ) {
$g3 = 10;
continue;
}
else {
$g3++;
}
}
}
if($g3 < 0) {
$arraycell['pr'] += $g3;
}
}
} return $arraycell;
}这是打印出来的几个log
[35] => Array
(
[code] =>
<span class="fl">
<label for="name">昵称:</label>
<input name="nickName" id="nickName" type="text" />
</span> [text] => 昵称:
[pr] => -10
[title] =>
[process] =>
) [36] => Array
(
[code] =>
<span>其他登录方式:</span>
<a href="http://ins.gao7.com/loginweibo2.aspx?access=1&pid=1&mode=1&back=aHR0cDovL3d3dy5nYW83LmNvbS9hcHAvMTE5MjQwMS02NjE5Mw==&safety=06b9Y3QwYmltZ2huY2NibDVsd2YwMjRvZjNl" class="focus-sina" rel="nofollow"></a>
<a href="http://ins.gao7.com/loginweibo2.aspx?access=1&pid=1&mode=2&back=aHR0cDovL3d3dy5nYW83LmNvbS9hcHAvMTE5MjQwMS02NjE5Mw==&safety=06b9Y3QwYmltZ2huY2NibDVsd2YwMjRvZjNl" class="focus-qq" rel="nofollow"></a> [text] => 其他登录方式:
[pr] => 0
[title] =>
[process] =>
) [37] => Array
(
[code] => <a href="javascript:exitLogin()">退出</a>
[text] => 退出
[pr] => -10
[title] =>
[process] =>
) [38] => Array
(
[code] =>
<a href="javascript:checkNull()" class="fr publish-btn" id="fbpl">发表评论</a> [text] => 发表评论
[pr] => -10
[title] =>
[process] =>
) [39] => Array
(
[code] =>
<h3>我要评论:</h3> [text] => 我要评论:
[pr] => 0
[title] =>
[process] =>
) [40] => Array
(
[code] =>
<span class="fl">
<label for="name">昵称:</label>
<input name="nickName" id="nickName-Yhpl" type="text" />
</span> [text] => 昵称:
[pr] => -10
[title] =>
[process] =>
)
function getpr($arraycell, $searchaborative, $replaceaborative) {
$htmltags = array(
array('title', 5),
array('a', -1),
array('iframe', -2),
array('p', 1),
array('li', -1),
array('input', -0.1),
array('select', -3),
array('form', -0.1)
);if(strlen($arraycell['text']) > 10) {
if(strlen($arraycell['text']) > 200) {
$arraycell['pr'] += 2;
}foreach($htmltags as $tagsvalue) {
$temp = array();
preg_match_all("/\<$tagsvalue[0][^\>]*?\>/is", $arraycell['code'], $temp, PREG_SET_ORDER);
$tagsnum = count($temp);$temp = array();
if($tagsvalue[0] == 'title' && $tagsnum > 0) {
$arraycell['title'] = 'title';
} elseif($tagsvalue[0] == 'a' && $tagsnum > 0) {
preg_match_all("/\<a[^\>]*?\>(.*?)\<\/a>/is", $arraycell['code'], $temp);
$temp[2] = preg_replace("/[\n\r\s]*?/is", '', preg_replace ($searchaborative, $replaceaborative, implode('', $temp[1])));
$ahretnum = strlen($temp[2]) / strlen($arraycell['text']);
$tagsnum *= $ahretnum * 10;
}$arraycell['pr'] += $tagsnum * $tagsvalue[1];
}
} else {
$arraycell['pr'] -= 10;
}if($arraycell['pr'] >= 0) {
$g1 = preg_replace("/\<(p|br)[^\>]*?\>/si", "\n\n###p br explode###\n\n", $arraycell['code']);
$arrayg1 = explode("\n\n###p br explode###\n\n", $g1);preg_match_all("/\n\n###p br explode###\n\n/is", $g1, $g4, PREG_SET_ORDER);if(count($g4) > 2) {
$g3 = 0;
foreach($arrayg1 as $value) {
$g2 = preg_replace("/[\n\r\s]*?/is", "", preg_replace ($searchaborative, $replaceaborative, $value));if($g2 != '') {
$g2num = strlen($g2);
if($g2num <= 25) {
$g3--;
} elseif($g2num > 70 ) {
$g3 = 10;
continue;
}
else {
$g3++;
}
}
}if($g3 < 0) {
$arraycell['pr'] += $g3;
}
}
}return $arraycell;
}
[35] => Array
(
[code] =>
<span class="fl">
<label for="name">昵称:</label>
<input name="nickName" id="nickName" type="text" />
</span> [text] => 昵称:
[pr] => -10
[title] =>
[process] =>
) [36] => Array
(
[code] =>
<span>其他登录方式:</span>
<a href="http://ins.gao7.com/loginweibo2.aspx?access=1&pid=1&mode=1&back=aHR0cDovL3d3dy5nYW83LmNvbS9hcHAvMTE5MjQwMS02NjE5Mw==&safety=06b9Y3QwYmltZ2huY2NibDVsd2YwMjRvZjNl" class="focus-sina" rel="nofollow"></a>
<a href="http://ins.gao7.com/loginweibo2.aspx?access=1&pid=1&mode=2&back=aHR0cDovL3d3dy5nYW83LmNvbS9hcHAvMTE5MjQwMS02NjE5Mw==&safety=06b9Y3QwYmltZ2huY2NibDVsd2YwMjRvZjNl" class="focus-qq" rel="nofollow"></a> [text] => 其他登录方式:
[pr] => 0
[title] =>
[process] =>
) [37] => Array
(
[code] => <a href="javascript:exitLogin()">退出</a>
[text] => 退出
[pr] => -10
[title] =>
[process] =>
) [38] => Array
(
[code] =>
<a href="javascript:checkNull()" class="fr publish-btn" id="fbpl">发表评论</a> [text] => 发表评论
[pr] => -10
[title] =>
[process] =>
) [39] => Array
(
[code] =>
<h3>我要评论:</h3> [text] => 我要评论:
[pr] => 0
[title] =>
[process] =>
) [40] => Array
(
[code] =>
<span class="fl">
<label for="name">昵称:</label>
<input name="nickName" id="nickName-Yhpl" type="text" />
</span> [text] => 昵称:
[pr] => -10
[title] =>
[process] =>
)