Jump to content

Recommended Posts

how to get the output of this code

 

<?php
class KeywordsGenerator{
   public function generateKeywords($string = '', $min_word_char = 4, $keyword_amount = 15,  $exclude_words = ''){
       return self::calculateKeywords($string, $min_word_char, $keyword_amount,  $exclude_words);
   }    
   private function calculateKeywords($string = '', $min_word_char = 3, $keyword_amount = 15,  $exclude_words = '' ) {        
       $exclude_words = explode(", ", $exclude_words);
       //add space before br tags so words aren't concatenated when tags are stripped
       $string = preg_replace('/\<br(\s*)?\/?\>/i', " ", $string);
       // get rid off the htmltags
       $string = html_entity_decode(strip_tags($string), ENT_NOQUOTES , 'UTF-8');        
       // count all words with str_word_count_utf8
       $initial_words_array  = self::str_word_count_utf8($string, 1);
       $total_words = sizeof($initial_words_array);        
       $new_string = $string;        
       //convert to lower case
       $new_string = mb_convert_case($new_string, MB_CASE_LOWER, "UTF-8");        
       // strip excluded words
       foreach($exclude_words as $filter_word)    {
           $new_string = preg_replace("/\b".$filter_word."\b/i", "", $new_string);
       }        
       // calculate words again without the excluded words using str_word_count_utf8
       $words_array = self::str_word_count_utf8($new_string, 1);
       $words_array = array_filter($words_array, create_function('$var', 'return (strlen($var) >= '.$min_word_char.');'));
       $popularity = array();
       $unique_words_array = array_unique($words_array);        
       // create density array
       foreach($unique_words_array as  $key => $word)    {
           preg_match_all('/\b'.$word.'\b/i', $string, $out);
           $count = count($out[0]);    
           $popularity[$key]['count'] = $count;
           $popularity[$key]['word'] = $word;            
       }        
       usort($popularity, array('MetaGenerator','cmp'));        
       // sort array form higher to lower
       krsort($popularity);        
       // create keyword array with only words
       $keywords = array();
       foreach($popularity as $value){
           $keywords[] = $value['word'];
       }                    
       // glue keywords to string seperated by comma, maximum 15 words
       $keystring =  implode(', ', array_slice($keywords, 0, $keyword_amount));        
       // return the keywords
       return $keystring;
   }    
   /**
    * Sort array by count value
    */
   private static function cmp($a, $B) {
       return ($a['count'] > $b['count']) ? +1 : -1;
   }
   /** Word count for UTF8
   /* Found in: http://www.php.net/%20str_word_count#85592
   /* The original mask contained the apostrophe, not good for Meta keywords:
   /* "/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}..."
   */
   private static function str_word_count_utf8($string, $format = 0) {
    switch ($format) {
    case 1:
	    preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}]*/u", $string, $matches);
	    return $matches[0];
    case 2:
	    preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}]*/u", $string, $matches, PREG_OFFSET_CAPTURE);
	    $result = array();
	    foreach ($matches[0] as $match) {
		    $result[$match[1]] = $match[0];
	    }
	    return $result;
    }
    return preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}]*/u", $string, $matches);
   }            
}
$text = "As you probably know, having great content is only part of the equation if you want to rank well in Google and receive organic traffic. The other part is promotion and backlinks.
Here are some methods you can use to promote each of your pages/posts once you publish them:
   * Email the URL of your page to bloggers in your niche saying they might find it interesting. And I don’t mean five or six of them. I mean email it to 100 bloggers and website owners. If you can’t find 100 in websites your niche, you aren’t trying hard enough.
   * Guest post on other blogs and, instead of linking to your homepage on the byline, link to the page you are trying to promote. Again, I am not talking about one or two guest posts, but ten or 20 for each page you publish targeting a long tail keyword.
   * Leverage social networks like Twitter and Facebook to promote the page, and perhaps create a contest to encourage people to share the page with their friends.
   * Post about your page on online forums, Q and A sites, social bookmarking sites, you name it. ";
echo KeywordsGenerator("$text");
?>

Link to comment
https://forums.phpfreaks.com/topic/269632-unable-to-get-class-output/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.