|
[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: |
Here is my code:
<?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
//code for body
//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='.$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==3)
{
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></Title> tags</th>
<th><p>Keyword in Title as %<br>
of all words in Title</p>
</th>
<th># of times keyword is <br>
in Description tags</th>
<th>Keyword in b as % <br>
of all words in Description</th>
<th># of times keyword is <br>
in <h1></h1> tags</th>
<th><p>Keyword in H1 as %<br>
of all words in Header 1s</p>
</th>
<th># of times keyword is <br>
in <b></b> tags</th>
<th>Keyword in b as % <br>
of all words in bold</th>
<th># of times keyword is <br>
in <body></body> tags</th>
<th>Keyword in <body> as % <br>
of all words in body.</th>
</tr>
<?php for($i=0;$i<count($urlarray);$i++){
// wait for 5 seconds = 5,000,000 HUMAN EMULATION
usleep(5000000);
?>
<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>
<td>
Title # result
</td>
<td>
Title % result
</td>
<td>
Description # result
</td>
<td>
Description % result
</td>
<td>
h1 # result
</td>
<td>
h1 % result
</td>
<td>
b # result
</td>
<td>
b % result
</td>
<td>
body # result
</td>
<td>
body % result
</td>
</tr>
<?php } ?>
</table>
</fieldset>
<?php
}
else if(isset($_REQUEST['Submit']))
{
echo 'Please Enter a URL.';
}
?>
</body>
<!--<?php include('includes/footer.php'); ?>-->
</html>
HERE IS ONE SOLUTION FROM EARLIER: (I could not get this to work at all)
$needle1 = "<h1>";
$needle2 = "</h1>";
$counter = substr_count($temp, $needle1);
//echo $counter;
$i=1;
while($i<=$counter){
$pos1 = stripos($temp, $needle1, $pos4+1);
$pos2 = $pos1+4;
$pos3 = stripos($temp, $needle2, $pos2);
$stuffinh1[] = substr($temp, $pos2, ($pos3-$pos2));
$pos4 = $pos1;
$i++;
}
HERE IS THE OTHER SOLUTION FROM EARLIER: (I got the code to run and print, but 1) there is an error and 2) I could not figure out how to integrate with my code.
<?php
$page="
<b>word2</b>
<b>word1 word3 word3 word2 word2</b>
<b>word2 word2 word5 word2 word3</b>
<b>word1 word2 word3 word4 word5</b>
<b>word1 word3 word3 word2 word2</b>
<b>word2 word2 word5 word2 word3</b>
<b>word1 word2 word3 word4 word5</b>
<h1>word1 word3 word3 word2 word2</h1>
<h1>word2 word2 word5 word2 word3</h1>
<h1>word1 word2 word3 word4 word5</h1>
<h2>word1 word 2 word3 word4</h2>
";
$keyword = "word2";
$counth1 = "0";
$countb = "0";
$keywords_counth1 = "0";
$keywords_countb = "0";
preg_match_all("%<h1>[\w\s]*(?<!\w)(?=\w)($keyword)(?<=\w)(?!\w)[\w\s]*</h1>%m", $page, $allh1tags);
preg_match_all("%<b>[\w\s]*(?<!\w)(?=\w)($keyword)(?<=\w)(?!\w)[\w\s]*</b>%m", $page, $allbtags);
$count = (count($allh1tags['0']) > (count($allh1tags['0']))) ? count($allbtags['0']) : count($allbtags['0']);
for($i=0;$i<$count;$i++)
{
@$counth1+=count(explode(" ", $allh1tags['0'][$i]));
@$keywords_counth1+=count(explode($keyword, $allh1tags['0'][$i]))-1;
@$countb+=count(explode(" ", $allbtags['0'][$i]));
@$keywords_countb+=count(explode($keyword, $allbtags['0'][$i]))-1;
}
print $counth1; // total of all matching keywords betwen ALL tags <h1> and <b> SUPPOSED TO BE JUST MATCHING H1.... 19 -- MATCHING <H1> & <B>
?>
<br>
<?php
print $keywords_counth1; // total number of matching keyword matches betwen <h1> tags 6 -- MATCHING <H1>
?>
<br>
<?php
print $countb; // total of all words betwen <b> tags 31 -- ALL <B>
?>
<br>
<?php
print $keywords_countb; // total number of keyword matches betwen b tags (YES) 13 -- MATCHING <B>
//based on above values you just do the math with them.
?>
|
Advertisement
| Hall of Fame |