|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: |
<?php
error_reporting(E_ALL ^ E_NOTICE);
//prevents script from timing out
set_time_limit(0);
//--> for google pagerank
function StrToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296; // 2^32
$length = strlen($Str);
for ($i = 0; $i < $length; $i++)
{
$Check *= $Magic;
//If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
// the result of converting to integer is undefined
if ($Check >= $Int32Unit)
{
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
//if the check less than -2^31
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
//--> for google pagerank
/*
* Genearate a hash for a url
*/
function HashURL($String)
{
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
//--> for google pagerank
/*
* genearate a checksum for the hash string
*/
function CheckHash($Hashnum)
{
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --)
{
$Re = $HashStr{$i};
if (1 === ($Flag % 2))
{
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte)
{
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) )
{
if (1 === ($CheckByte % 2))
{
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
//get google pagerank
function getpagerank($url)
{
$query="http://toolbarqueries.google.com/search?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
$data=file_get_contents_curl($query);
//print_r($data);
$pos = strpos($data, "Rank_");
if($pos === false){} else
{
$pagerank = substr($data, $pos + 9);
return $pagerank;
}
}
//code for h1
//code for b
//for POST request with curl
function do_post_request_curl($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // add POST fields
$result = curl_exec($ch); // run the whole process
//echo $result;
curl_close($ch);
return $result;
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function getUrl ($sel_keyword) {
$arrLinks=array();
$cnt=0;
$url = 'http://www.google.com/search?hl=en&q='.urlencode($sel_keyword).'&btnG=Google+Search&aq=f&oq=';
// $url = 'http://www.google.com/search?hl=en&q='.$sel_keyword.'&btnG=Google+Search&aq=f&oq=';
$str = "'".file_get_contents($url)."'";
$h1count = preg_match_all('/\<li class=g\>\<h3 class=r\>\<a href="(.*?)" class=l\>/',$str,$patterns);
$href_add = $patterns[1];
if(!empty($href_add[0]))
{
foreach($href_add as $key => $val)
{
$val = preg_replace("/</","<a",$val);
//echo "<li>" . htmlentities($val) . "</li>";
$arrLinks[$cnt]=htmlentities($val);
++$cnt;
//number of urls code CJ
if($cnt==1)
{
break;
}
}
echo "</ul>";
}
return $arrLinks;
}
?>
<!--<?php include('includes/header.php');?>-->
<body>
<form id="form1" name="form1" method="get" action="">
KEYWORD:
<input name="keyword" type="text" id="keyword" value="<?php echo $_REQUEST['keyword']; ?>" />
URL :
<input name="url" type="text" size="30" id="url" value="<?php echo $_REQUEST['url']; ?>" />
<input type="submit" name="Submit" value="Submit" />
<br>
<br>
</form>
<?php
if ((isset($_REQUEST['Submit'])) && ($_REQUEST['url']!='')) {
?>
<fieldset>
<legend>Query result</legend>
<?php
$urlarray = array();
$urlarray[0]=$_REQUEST['url'];
$arrLinks=getUrl($_REQUEST['keyword']);
for($i=0,$j=1;$i<count($arrLinks);$i++,$j++){
$urlarray[$j]=$arrLinks[$i];
}
?>
<table border=1 width="80%">
<tr>
<th>Link</th>
<th>Google pagerank</th>
<th># of times keyword is <br>
in Title tags</th>
<th><p>Keyword in Title as %<br>
of all words in Title</p>
</th>
<th># of times keyword is <br>
in <h1></h1> tags</th>
<th>Keyword in h1 as % <br>
of all words in h1</th>
<th># of times keyword is <br>
in <h2-6></h2-6> tags</th>
<th>Keyword in h2-h6 as % <br>
of all words in h2-h6</th>
<th># of times keyword is <br>
in bold tags</th>
<th>Keyword in bold as % <br>
of all words in bold</th>
<th># of times keyword is <br>
in body tags</th>
<th>Keyword in body as % <br>
of all words in body</th>
<th># of times keyword is <br>
in links tags</th>
<th>Keyword in links as % <br>
of all words in links</th>
<th># of times keyword is <br>
in meta description</th>
<th>Keyword in meta description as % <br>
of all words in meta description</th>
</tr>
<?php for($i=0;$i<count($urlarray);$i++){
// wait for 5 seconds = 5,000,000 HUMAN EMULATION
//usleep(5000000);
//Have a bit of a rest before we go check the next keyword 3-6 seconds
sleep(rand(5,10));
?>
<tr>
<td>
<?php
if($i==0){
?>
<a href="<?php echo $urlarray[$i];?>" style="color:blue"><?php echo $urlarray[$i];?></a>
<?php
}
else{
?>
<a href="<?php echo $urlarray[$i];?>"><?php echo $urlarray[$i];?></a>
<?php
}
?>
</td>
<td>
<?php echo getpagerank($urlarray[$i]);?>
</td>
<?php
# 1 Get the html for the page
$page_contents = file_get_contents($urlarray[$i]);
# 2 Distill the <body> section from the page content
$body_content = preg_replace('/^(.*)(<body(.*)<\/body>)(.*)/ims', '\2', $page_contents);
# 3 Store the keyword in a local variable
$keyword = $_REQUEST['keyword'];
# 4 Test the h1's for keywords
$all_h1_words_string = '';
$all_h1_words_array = array();
$all_hX_words_string = '';
$all_hX_words_array = array();
# 4.1 Find all h1 tags, store all separate words in an array as well as a string
if(preg_match_all('#<h1>(.*?)</h1>#ims', $page_contents, $m)) {
$all_h1_words_string = strip_tags(implode('.', $m[1]));
$all_h1_words_array = preg_split('/[^\w\-\']+/', $all_h1_words_string);
}
# 4.2 Count the number of times the keyword is in the string with all h1 contents
$num_keyword_in_h1 = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_h1_words_string, $m) ? count($m[0]) : 0;
# 4.3 Compare the counted number with the amount of words, taking into account that a division by zero error should be prevented
if($num_keyword_in_h1 == 0 || count($all_h1_words_array) == 0) {
$prc_keyword_in_h1 = 0;
} else {
$prc_keyword_in_h1 = (100 / count($all_h1_words_array) * $num_keyword_in_h1);
}
# 4.4 Find all h1 tags, store all separate words in an array as well as a string
if(preg_match_all('#<h[2-6]>(.*?)</h[2-6]>#ims', $page_contents, $m)) {
$all_hX_words_string = strip_tags(implode('.', $m[1]));
$all_hX_words_array = preg_split('/[^\w\-\']+/', $all_hX_words_string);
}
# 4.5 Count the number of times the keyword is in the string with all h1 contents
$num_keyword_in_hX = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_hX_words_string, $m) ? count($m[0]) : 0;
# 4.6 Compare the counted number with the amount of words, taking into account that a division by zero error should be prevented
if($num_keyword_in_hX == 0 || count($all_hX_words_array) == 0) {
$prc_keyword_in_hX = 0;
} else {
$prc_keyword_in_hX = (100 / count($all_hX_words_array) * $num_keyword_in_hX);
}
$all_title_words_string = '';
$all_title_words_array = array();
# 4.7 Find all h1 tags, store all separate words in an array as well as a string
if(preg_match_all('#<title>(.*?)</title>#ims', $page_contents, $m)) {
$all_title_words_string = strip_tags(implode('.', $m[1]));
$all_title_words_array = preg_split('/[^\w\-\']+/', $all_title_words_string);
}
# 4.8 Count the number of times the keyword is in the string with all h1 contents
$num_keyword_in_title = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_title_words_string, $m) ? count($m[0]) : 0;
# 4.9 Compare the counted number with the amount of words, taking into account that a division by zero error should be prevented
if($num_keyword_in_title == 0 || count($all_title_words_array) == 0) {
$prc_keyword_in_title = 0;
} else {
$prc_keyword_in_title = (100 / count($all_title_words_array) * $num_keyword_in_title);
}
$all_bold_words_string = '';
$all_bold_words_array = array();
# 4.1 Find all bold tags, store all separate words in an array as well as a string
if(preg_match_all('#<b>(.*?)</b>#ims', $page_contents, $m)) {
$all_bold_words_string = strip_tags(implode('.', $m[1]));
$all_bold_words_array = preg_split('/[^\w\-\']+/', $all_bold_words_string);
}
# 4.2 Count the number of times the keyword is in the string with all bold contents
$num_keyword_in_bold = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_bold_words_string, $m) ? count($m[0]) : 0;
# 4.3 Compare the counted number with the amount of words, taking into account that a division by zero error should be prevented
if($num_keyword_in_bold == 0 || count($all_bold_words_array) == 0) {
$prc_keyword_in_bold = 0;
} else {
$prc_keyword_in_bold = (100 / count($all_bold_words_array) * $num_keyword_in_bold);
}
# 5. Test the <b>'s for keywords. (Similar to bold)
# $all_bold_words_string = '';
# $all_bold_words_array = array();
# 5.1
# if(preg_match_all('#<b>(.*?)</b>#ims', $page_contents, $m)) {
$all_bold_words_string = implode('.', $m[1]);
$all_bold_words_array = preg_split('/[^\w\-\']+/', $all_bold_words_string);
# echo '<p><b>ALL bold words(need a stop list):</b> '.implode(',', $all_bold_words_array).'</p>';
# }
# 5.2
# $num_keyword_in_bold = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_bold_words_string, $m) ? count($m[0]) : 0;
# 5.3 (same as 4.3 but in ternairy expression: $value = $somebooleanexpression ? $value_if_expression_is_true : $value_if_expression_is_false
# $prc_keyword_in_bold = $num_keyword_in_bold == 0 || count($all_bold_words_array) == 0 ? 0 : (100 / count($all_bold_words_array) * $num_keyword_in_bold);
# 6. Test the body. We don't use a array for storing all words, as that might get memory intensive
# $num_keyword_in_body = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', strip_tags($body_content), $m) ? count($m[0]) : 0;
$num_words_in_body = count(preg_split('/[^\w\-\']+/', strip_tags($body_content)));
$prc_keyword_in_body = $num_keyword_in_body == 0 || $num_words_in_body == 0 ? 0 : (100 / $num_words_in_body * $num_keyword_in_body);
# 7. Test the <b>'s for keywords. (Similar to bold)
$all_bold_words_string = '';
$all_bold_words_array = array();
# 7.1
if(preg_match_all('#<b>(.*?)</b>#ims', $page_contents, $m)) {
$all_links_words_string = implode('.', $m[1]);
$all_links_words_array = preg_split('/[^\w\-\']+/', $all_links_words_string);
echo '<p><b>ALL links words (need a stop list):</b> '.implode(',', $all_links_words_array).'</p>';
}
# 7.2
$num_keyword_in_links = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_links_words_string, $m) ? count($m[0]) : 0;
# 7.3 (same as 4.3 but in ternairy expression: $value = $somebooleanexpression ? $value_if_expression_is_true : $value_if_expression_is_false
$prc_keyword_in_links = $num_keyword_in_links == 0 || count($all_links_words_array) == 0 ? 0 : (100 / count($all_links_words_array) * $num_keyword_in_links);
# 8. Test the metadescriptions for keywords. ()
$all_metadesciption_words_string = '';
$all_metadescription_words_array = array();
# 8.1
if(preg_match_all('#<meta name=\"description\" content=\"([^\"]+)#ims', $page_contents, $m)) {
//if(preg_match_all('#<meta name=\"description\" content=\".*?%s.*?#ims', $page_contents, $m)) {
$all_metadescription_words_string = implode('.', $m[1]);
$all_metadescription_words_array = preg_split('/[^\w\-\']+/', $all_metadescription_words_string);
echo '<p><b>ALL meta description words(need a stop list):</b> '.implode(',', $all_metadescription_words_array).'</p>';
}
# 8.2
$num_keyword_in_metadescription = preg_match_all('/(^|\W)'.preg_quote($keyword).'(\W|$)/i', $all_metadescription_words_string, $m) ? count($m[0]) : 0;
# 8.3 (same as 4.3 but in ternairy expression: $value = $somebooleanexpression ? $value_if_expression_is_true : $value_if_expression_is_false
$prc_keyword_in_metadescription = $num_keyword_in_metadescription == 0 || count($all_metadescription_words_array) == 0 ? 0 : (100 / count($all_metadescription_words_array) * $num_keyword_in_metadescription);
# 9. Output: For the count, I used number_of_matches / number_of_words instead of only number_of_matches. This allows for better debugging for the time being
?>
<td>
<?php printf('%d / %d', $num_keyword_in_title, count($all_title_words_array));?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_title);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_h1, count($all_h1_words_array));?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_h1);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_hX, count($all_hX_words_array));?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_hX);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_bold, count($all_bold_words_array));?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_bold);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_body, $num_words_in_body);?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_body);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_links, $num_words_in_links);?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_links);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_metadescription, $num_words_in_metadescription);?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_metadescription);?>
</td>
</tr>
<?php } ?>
</table>
</fieldset>
<?php
}
else if(isset($_REQUEST['Submit']))
{
echo 'Please Enter a URL.';
}
?>
</body>
<!--<?php include('includes/footer.php'); ?>-->
</html>
|
Advertisement
| Hall of Fame |