Jump to content

the5thace

Members
  • Posts

    26
  • Joined

  • Last visited

the5thace's Achievements

Member

Member (2/5)

0

Reputation

  1. Ah, thanks what do I need to do in case of Warning: file_put_contents(Blekko.txt) [function.file-put-contents]: failed to open stream: Permission denied in /home/msc2012/12254822/public_html/safe_dir/Almost_Gs.php on line 369
  2. I'm just trying to load some of the echoed results in to a txt file that I can use myself. I assumed that there should be a txt file in my server directory but no file has been created. What am I doing wrong? while ($blekr<=$blekko_count) { echo '<a href='.$Blekko[$blekr]['url'].'><h4>'.$Blekko[$blekr]['url_title'].'</h4></a>'; echo '<p>'.$Blekko[$blekr]['snippet'].'<p>'; echo '<b>'.$Blekko[$blekr]['engine'].'</b>'; $file = 'Blekko.txt'; file_put_contents($file, $Blekko[$blekr]['url'], FILE_APPEND); echo '<hr>'; $blekr++; } The echo statements run fine but no file anywhere to be found. There isn't anything said in the manual either ...
  3. Notice: Undefined variable: bing_results in /home/msc2012/12254822/public_html/safe_dir/Almost_Gs.php on line 295 Basically, its the 'Interleaving' case that does not work as the echoed variables are not recognized when run on the server but the IDE does not highlight them as errors so it recognizes them. If you pay attention further down the switch statement under other cases I use the same variable $bing_results where it works and is recognized by the server. The scenario is the same with $Blekko and $Google case 'Interleaving': $irl =0; while($irl <= 90) { echo 'hellooo!!'; echo '<a href ='.$bing_results[$irl]['url'].'><h5>'.$bing_results[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$bing_results[$irl]['snippet'].'</p><br>'; echo '<p>'.$bing_results[$irl]['rank'].'<p><br>'; echo '<b>'.$bing_results[$irl]['engine'].'</b><br>'; echo '<hr>'; echo '<a href ='.$Blekko[$irl]['url'].'><h5>'.$Blekko[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$Blekko[$irl]['snippet'].'</p><br>'; echo '<p>'.$Blekko[$irl]['rank'].'<p><br>'; echo '<b>'.$Blekko[$irl]['engine'].'</b><br>'; echo '<hr>'; echo '<a href ='.$google[$irl]['url'].'><h5>'.$google[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$google[$irl]['snippet'].'</p><br>'; echo '<p>'.$google[$irl]['rank'].'<p><br>'; echo '<b>'.$google[$irl]['engine'].'</b><br>'; echo '<hr>'; $irl++; } break; case 'Non-Aggregated': $nag_c=0; // non aggregated count while ($nag_c <=$blekko_count) { echo '<a href='.$Blekko[$nag_c]['url'].'><h4>'.$Blekko[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$Blekko[$nag_c]['snippet'].'<p>'; echo '<b>'.$Blekko[$nag_c]['engine'].'</b>'; echo '<hr>'; $nag_c++; } $nag_c =0; while ($nag_c <= $google_count) { echo '<a href='.$google[$nag_c]['url'].'><h4>'.$google[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$google[$nag_c]['snippet'].'</p><br>'; echo '<b>'.$google[$nag_c]['engine'].'</b><br>'; echo '<hr>'; $nag_c++; } $nag_c=0; while ($nag_c<=$bing_count) { echo '<a href='.$bing_results[$nag_c]['url'].'>'.'<h4>'.$bing_results[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$bing_results[$nag_c]['snippet'].'</p>'; echo '<b>'.$bing_results[$nag_c]['engine'].'</b>'; echo '<hr>'; $nag_c++; } case 'Bing': $binger = 0; while ($binger<=$bing_count) { echo '<a href='.$bing_results[$binger]['url'].'>'.'<h4>'.$bing_results[$binger]['url_title'].'</h4></a>'; echo '<p>'.$bing_results[$binger]['snippet'].'</p><br>'; echo '<b>'.$bing_results[$binger]['engine'].'</b><br>'; echo '<hr>'; $binger++; } break; case 'Blekko': $blekr = 0; while ($blekr<=$blekko_count) { echo '<a href='.$Blekko[$blekr]['url'].'><h4>'.$Blekko[$blekr]['url_title'].'</h4></a>'; echo '<p>'.$Blekko[$blekr]['snippet'].'<p>'; echo '<b>'.$Blekko[$blekr]['engine'].'</b>'; echo '<hr>'; $blekr++; } break; case 'Google': $froo = 0; while ($froo <=$google_count) { echo '<a href='.$google[$froo]['url'].'><h4>'.$google[$froo]['url_title'].'</h4></a>'; echo '<p>'.$google[$froo]['snippet'].'</p>'; echo '<b>'.$google[$froo]['engine'].'</b>'; echo '<hr>'; $froo++; } break; } ?>
  4. echo still ends with dog+not+cat $Bquery = urlencode($_POST['query']); if ( strpos( strtoupper($Bquery), "NOT")!==false ) { $findme = ' NOT '; if (substr($Bquery, 0, 4)=='NOT ') { $new="-".substr($Bquery, 4); } else { $new=str_replace($findme, ' -', $Bquery); } echo $new;
  5. Sample string: "cats NOT dogs". How would I replace that with "cats -dogs"? Notice there is no space between the -dog but there was a space between NOT dog. This should be applicable to any string.
  6. I'm looking to sort this multidimensional array according to its integer value under the key name 'rank'. In other words $r_set contains the combined results of a number of search engines and each result is assigned a 'rank' according to which I want the array to be sorted. $r_set contents look like this -> $google[$google_count] = array ('url'=>$item->link, 'url_title'=>$item->title, 'snippet' =>$item->htmlSnippet, 'rank' => 100-$google_count, 'engine' => 'Google'); $google_count++; I load a number of these kinds of results(.ie $google[google_count] and others like it) in to $r_set when they have the same structure. I want $r_set to be sorted by its 'rank' key starting highest to lowest.
  7. Ok, I understand. Thank you for your reply. I was actually looking to parse the synonyms offered by the var dump in to an array. "Domestic dog[1]" and "Caninis Familirialis[2]". So I was attempting to have each one of these synonyms as $object[$ob_c] and echo them.
  8. I don't follow .... I have parsed similar files before like this which works curl_setopt($ch, CURLOPT_URL, $fullUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $data=curl_exec($ch); $js = json_decode($data); $blekko_count=0; $rank=100; foreach ($js->RESULT as $item) { $Blekko[$blekko_count] = array ('url'=>$item->url, 'url_title' =>$item->url_title, 'snippet' =>$item->snippet, 'rank' => 100 - $blekko_count, 'engine' => 'Blekko'); $blekko_count++;
  9. This is the var_dump of a json_decode function. How do I parse it with a foreach and load it in to an array? object(stdClass)#1 (2) { ["noun"]=> object(stdClass)#2 (1) { ["syn"]=> array(39) { [0]=> string(12) "domestic dog" [1]=> string(16) "Canis familiaris" [2]=> string(5) "frump" [3]=> string(3) "cad" [4]=> string(7) "bounder" [5]=> string(10) "blackguard" [6]=> string(5) "hound" [7]=> string(4) "heel" [8]=> string(5) "frank" [9]=> string(11) "frankfurter" [10]=> string(6) "hotdog" [11]=> string(7) "hot dog" [12]=> string(6) "wiener" [13]=> string(11) "wienerwurst" [14]=> string(6) "weenie" [15]=> string(4) "pawl" [16]=> string(6) "detent" [17]=> string(5) "click" [18]=> string(7) "andiron" [19]=> string(7) "firedog" [20]=> string( "dog-iron" [21]=> string( "blighter" [22]=> string(5) "canid" [23]=> string(6) "canine" [24]=> string(5) "catch" [25]=> string(4) "chap" [26]=> string(4) "cuss" [27]=> string(18) "disagreeable woman" [28]=> string(5) "fella" [29]=> string(6) "feller" [30]=> string(6) "fellow" [31]=> string(4) "gent" [32]=> string(3) "lad" [33]=> string(7) "sausage" [34]=> string(9) "scoundrel" [35]=> string(4) "stop" [36]=> string(7) "support" [37]=> string(16) "unpleasant woman" [38]=> string(7) "villain" } } ["verb"]=> object(stdClass)#3 (2) { ["syn"]=> array(10) { [0]=> string(5) "chase" [1]=> string(11) "chase after" [2]=> string(5) "trail" [3]=> string(4) "tail" [4]=> string(3) "tag" [5]=> string(10) "give chase" [6]=> string( "go after" [7]=> string(5) "track" [8]=> string(6) "follow" [9]=> string(6) "pursue" } ["rel"]=> array(2) { [0]=> string(10) "chase away" [1]=> string(9) "tag along" } } } if ($_POST['query']) { $word = ($_POST['query']); $fullquery = 'http://words.bighugelabs.com/api/2/2b1ae894d9e4acd1517b457666fc9431/'.$word.'/json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $fullquery); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data=curl_exec($ch); $js = json_decode($data); var_dump($js); $ob_c=0; foreach ($js -> noun as $object[$ob_c]) { echo $object[$ob_c].'<br>'; $ob_c++; } }
  10. I'f I do a var_dump after taking in the array from the foreach statement then all of the variables are present. However, by the time the variables go through the switch statement and we run the first case it only prints out the URL for most of the results and URL_title for others. foreach ($js -> results as $item) { $Faroo[$o] = array ('url'=>$item->url, 'url_title'=>$item->title, 'snippet' =>$item->kwic, 'rank' => 100-$o, 'engine' => 'Faroo'); //var_dump($Faroo[$o]); $o++; } $s=$s+10; $e=$e+10; } } ?> <?php $agg = $_POST['agg']; $full_count=0; switch ($agg) { case 'Aggregated': while ($full_count<=$bing_count) //while m <= bing results m = 0; { $r_set[$full_count] = $bing_results[$full_count]; //load bing[m] in to r_set[m] $full_count++; //m = increments for every bing result } $b_count=0; $r_count=0; //reset b_count so we can start again and create r_count so we can loop through the existing unilist while ($b_count<$blekko_count) // 0 < blekko { // We reset postion in while ( $Blekko[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; //increment z to loop through the full r_set if ($r_count>$full_count) //When r_count counts through the full_count break (after finding all the matches)//should that not be b_count? { break; } } if ( $Blekko[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set[$r_count]['rank']+=$Blekko[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]=$Blekko[$b_count]; $b_count++; //if r_count is not larger then full count and url's do not match then we increment b_count } } $b_count=0; $r_count=0; //reset both counters again while ($b_count<$o) { // We reset postion in while ( $Faroo[$b_count]['url']!=$r_set[$r_count]['url']) { //check that the url is not already in the list $r_count++; if ($r_count>$full_count) { break; } } if ( $Faroo[$b_count]['url'] == $r_set[$r_count]['url']) { //if it is in the list then add the score $r_set['rank'][$r_count]+=$Faroo[$b_count]['rank']; $b_count++; //move to next element } else { //if not in the list then add it $full_count++; //y is used to increment on from this point $r_set[$full_count]= $Faroo[$b_count]; $b_count++; } } echo $full_count; array_multisort($r_set, SORT_ASC, 'rank'); //not sure if this works or not yet $echo_l = 0; while ($echo_l<=$full_count) { echo 'URL: '.$r_set[$echo_l]['url'].'<br>'; echo 'URL TITLE: '.$r_set[$echo_l]['url_title'].'<br>'; echo 'SNIPPET: '.$r_set[echo_l]['snippet'].'<br>'; echo 'RANK: '.$r_set[echo_l]['rank'].'<br>'; echo 'ENGINE: '.$r_set[echo_l]['engine'].'<br>'; var_dump($Blekko[$echo_l]); $echo_l++; }
  11. Fatal error: Cannot use string offset as an array in /..../ on line 6 { $bing_results[$b] = array ('url' => $value->Url, 'title' => $value->Title, 'snippet' => $value->Description, 'rank' => 100-$b); echo 'Lets see? : '.$bing_results[$b]['url']['title']['snippet']['rank']; $b++; }
  12. The following script no longer returns any results. I have loaded search engine results in to multidimensional arrays. Then I compare the different search engine result sets in order to find url matches. I create one main array for all the scores. I load one results set in to the main array and then compare the url's of it with the second results set. If there is a match then I add the scores if not then the full result goes to the bottom of the main array. I repeat the process wit the third results set. I finish it by trying to sort it. $i=0; foreach ($js->RESULT as $item) { $Blekko[$i] = array ('url'=>$item->url, 'url_title' =>$item->url_title, 'snippet' =>$item->snippet, 'rank' => 100-$i); } ^ We read in results in to a multidimensional array. Same is applied for the other two search engines that we aggregate. $m=0; $j=0; switch ($agg) { case 'Aggregated': while ($m<=$b) { $r_set[$m] = $bing_results[$m]; //load bing result in to main array $m++; } while ($j<=$b) { if ($r_set[$j]-->'url' === $Blekko[$j]-->'url') //compare bing url with blekko url for match { $r_set[$j]['rank'] = $r_set[$j]['rank'] + $Blekko[$j]['rank']; //if match add the ranks together } else { $r_set[$m] = $blekko[$j]; $m++; // if no match then we send the blekko array to the bottom of main array } $j++; } $reset = 0; while ($reset <= $i+$b) { if ($r_set[$reset]-->'url' === $Faroo[$reset]-->'url') //same procedure { $r_set[$reset]['rank'] = $r_set[$reset]['rank'] + $Faroo[$reset]['rank']; } else { $r_set[$m] = $Faroo[$reset]; $m++; } $reset++; } array_multisort($r_set, SORT_ASC, 'rank'); //sort the array by rank score $echo_l = 0; while ($echo_l<=$m) { echo $r_set[$echo_l]; $echo_l++; }
  13. The variable $q_words[$loop_count-1] is shown in the top besides Did you mean? but it fails to come up inside of the hyperlink. Any ideas to why? <?php if ($_POST['query']) { $query = ($_POST['query']); $q_words = explode (" ", $query); $loop_count = 0; $q_count = count(q_words); $s_count = 0; $ss_count = 0; while ($loop_count <= $q_count ) { $query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$q_words[$loop_count].'?key=135a6187-af83-4e85-85c1-1a28db11d5da'; $xml = new SimpleXMLIterator(file_get_contents($query)); foreach ($xml -> suggestion as $suggestion[$s_count]) { $s_count++; } if ($s_count > 1) { echo ('<h4>Did you mean ....? '.$q_words[$loop_count-1].'</h4>'); while ($ss_count <=$s_count) { echo '<a href = "AllinOneMonstaaa.php?query='.$q_words[loop_count-1].' '.$suggestion[$ss_count].'">'.$q_words[loop_count-1].' '.$suggestion[$ss_count].'</a><br>'; $ss_count++; } } $loop_count++; } }
  14. I'm trying to get a query expansion sort of effect that shows suggestions for misspellings and then lets you click them to input them in to your form. So I have passed a variable through a hyperlink but I can't seem to GET it in to the "value" field <form method="POST" action='AllinOneMonstaaa.php'> <label for="query">Query</label><br/> <input name="query" type="text" size="60" maxlength="60" value="<?php echo ($_GET['query']);?>" /><br /><br /> Notice the $_GET. I want it to be auto-filled if a user has selected an option in the previous page from the following php file. if ($s_count > 1) { echo ('<h4>Did you mean?</h4>'); while ($ss_count <=$s_count) { echo '<a href = "AllinOneMonstaaa.php?query='.$suggestion[$ss_count].'">'.$suggestion[$ss_count].'</a><br>'; $ss_count++; } }
  15. I more or less copied $query = ("'{$_POST['query']}'"); from Bing api booklet and never thought to question how it could interfere. Thanks for the answer.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.