当前位置: 首页>>代码示例>>PHP>>正文


PHP str_word_count函数代码示例

本文整理汇总了PHP中str_word_count函数的典型用法代码示例。如果您正苦于以下问题:PHP str_word_count函数的具体用法?PHP str_word_count怎么用?PHP str_word_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了str_word_count函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: recursiveMenuSideBar

function recursiveMenuSideBar($id_cha)
{
    $categories = DB::table('categories')->where('parent_id', '=', $id_cha)->get();
    $word = array();
    foreach ($categories as $category) {
        $numOfWord = str_word_count($category->name);
        $word = explode(' ', $category->name);
        $link = '';
        if ($numOfWord > 1) {
            for ($i = 0; $i < $numOfWord; $i++) {
                $link .= $word[$i];
            }
        } else {
            $link = $category->name;
        }
        echo "<option><a href='http://localhost/HungNH/public/{$link}'>";
        $name = '';
        for ($i = 0; $i < $category->level; $i++) {
            $name .= '&nbsp&nbsp';
        }
        $name .= '' . $category->name;
        echo $name;
        echo "</option>";
        $haveChild = haveChild($category->id);
        if ($haveChild > 0) {
            recursiveMenuSideBar($category->id);
        }
    }
}
开发者ID:hunguetit,项目名称:Laravel-Ex,代码行数:29,代码来源:sidebar.blade.php

示例2: umwords_build

function umwords_build($p, $o)
{
    $ratio = 50;
    $min = $p * $ratio;
    $limit = $min . ', ' . ($min + $ratio);
    $r = sql_inner('pub_art.id,msg', 'qda', 'qdm', 'id', 'kv', 'where nod="ummo" limit ' . $limit);
    if ($r) {
        foreach ($r as $k => $v) {
            $v = str_replace("'", ' ', $v);
            //$v=str_replace('-',' ',$v);
            $rb = str_word_count($v, 2);
            if ($rb) {
                foreach ($rb as $ka => $va) {
                    if ($va == strtoupper($va) && !umwords_dicos($va) && strlen($va) > 1) {
                        $rd[] = array($k, $va, $ka, soundex($va));
                        //idart,voc,pos,sound
                        $rc[$va] = array($k, $va, $ka, soundex($va));
                    }
                }
            }
        }
    }
    //if(auth(6))umwords_sav($rc);
    return $rd;
    $ret = count($rc);
    $ret .= make_table($rc);
    return $ret;
}
开发者ID:philum,项目名称:cms,代码行数:28,代码来源:umwords.php

示例3: contentSearch

function contentSearch($url)
{
    $dom = new DOMDocument();
    @$dom->loadHTMLFile($url);
    //$dom->loadHTML( '<?xml encoding="UTF-8">' . $content );
    $output = array();
    $csv_file = $_POST['csv_file'];
    $xpath = new DOMXPath($dom);
    $textNodes = $xpath->query('//text()');
    foreach ($textNodes as $textNode) {
        $parent = $textNode;
        while ($parent) {
            if (!empty($parent->tagName) && in_array(strtolower($parent->tagName), array('pre', 'code', 'a')) && str_word_count($parent->nodeValue) > 6) {
                continue 2;
            }
            if (str_word_count($parent->nodeValue) < 6 && !empty($parent->tagName)) {
                $job_title_file = fopen("{$csv_file}" . ".csv", 'r');
                while ($row = fgetcsv($job_title_file)) {
                    $nv = strip_tags($parent->nodeValue);
                    if (preg_match("/\\b" . $row[0] . "\\b/i", $nv)) {
                        //job title found
                        //echo $parent->tagName . '===' . $parent->nodeValue . '===' .  $row[0] . '<br />';
                        $output[] = array($nv, '');
                        fclose($job_title_file);
                        break;
                    }
                }
            }
            $parent = $parent->parentNode;
        }
        //end while parent
    }
    //end  for
    return $output;
}
开发者ID:sarangpatel,项目名称:jobscrapperv2,代码行数:35,代码来源:job_tracker_10sep2015.php

示例4: findWord

/**
 * findWord
 *
 * Compute the word that contains the highest number of repeated charaters
 * from the supplied text file
 *
 * @param  string $filePath The search text
 * @return string       The word with the highest number of charaters
 */
function findWord($filePath)
{
    if (!is_readable($filePath)) {
        throw new \RuntimeException(sprintf('The file path \'%s\' is not readable.', $filePath));
    }
    $text = file_get_contents($filePath);
    if (false === $text) {
        throw new \RuntimeException(sprintf('An error occured while trying to read the contents of \'%s\'', $filePath));
    }
    if (empty($text)) {
        throw new \DomainException(sprintf('The text file \'%s\' contains no text!', $filePath));
    }
    $winningWord = null;
    $charCount = 0;
    foreach (str_word_count(strtolower($text), 1) as $word) {
        $counts = count_chars($word, 1);
        if (!empty($counts)) {
            rsort($counts);
            $count = current($counts);
            if ($charCount == 0 || $count > $charCount) {
                $winningWord = $word;
                $charCount = $count;
            }
        }
    }
    return $winningWord;
}
开发者ID:alex-patterson-webdev,项目名称:arp-word-match,代码行数:36,代码来源:findword.php

示例5: isValid

 /**
  * Checks if the given value matches the specified maximum words.
  *
  * @param mixed $value The value that should be validated
  * @return void
  */
 public function isValid($value)
 {
     $maximumWords = $this->options['maximumWords'];
     if (str_word_count($value) > $maximumWords) {
         $this->addError('Verringern Sie die Anzahl der Worte - es sind maximal ' . $maximumWords . ' erlaubt!', 1383400016);
     }
 }
开发者ID:thomasNu,项目名称:simpleblog,代码行数:13,代码来源:WordValidator.php

示例6: truncateWords

 /**
  * Return a truncated string by the number of words
  */
 public static function truncateWords($str, $words)
 {
     if (str_word_count($str) > $words) {
         $str = trim(preg_replace('/((\\w+\\W*){' . $words . '}(\\w+))(.*)/', '${1}', $str)) . '&hellip;';
     }
     return $str;
 }
开发者ID:ErickLopez76,项目名称:offiria,代码行数:10,代码来源:xstring.php

示例7: get_keyword

 /**
  * Get a single keyword from a string or array of sanitized words.
  *
  * @access private
  *
  * @param string|array $words Array or string of sanitized words
  * 
  * @return string A single keyword
  */
 private function get_keyword($words)
 {
     // Make a string from array if array is provided
     if (is_array($words)) {
         $words = implode(' ', $words);
     }
     // Get an array of all words contained in the string
     $words = str_word_count($words, 1);
     // Get the count of all words
     $total_words = count($words);
     // Count all the values in the array and sort by values
     $word_count = array_count_values($words);
     arsort($word_count);
     // Holder for parsed words
     $new_words = array();
     // Loop through the words and score each into a percentage of word density
     foreach ($word_count as $key => $value) {
         $new_words[$key] = number_format($value / $total_words * 100);
     }
     // Pop the first word off the array
     reset($new_words);
     $first_key = key($new_words);
     // And return it
     return $first_key;
 }
开发者ID:rcoll,项目名称:WP_MLT_Query,代码行数:34,代码来源:wp_mlt_query.php

示例8: bind_listdomains

function bind_listdomains()
{
    $array_listado = array();
    $lines = file(_CFG_BIND_CFG_FILE);
    $i = 0;
    foreach ($lines as $line_num => $line) {
        if (substr($line, 0, 2) != "//") {
            $cadena = str_word_count($line, 1);
            if ($cadena[0] == "zone") {
                $linea_zona = trim($line);
                $pos_ini = strpos($linea_zona, '"');
                $pos_fin = strpos($linea_zona, '"', $pos_ini + 1);
                $zona = substr($linea_zona, $pos_ini + 1, $pos_fin - strlen($linea_zona));
                if (!word_exist($zona, _CFG_BIND_IGNORE_FILE)) {
                    $array_listado[$i] = trim($zona);
                    $i++;
                }
            }
            if ($cadena[0] == "file") {
                $linea_fichero = trim($line);
                $pos = strpos($linea_fichero, '"');
                $fichero = trim(substr($linea_fichero, $pos + 1, -2));
            }
        }
    }
    sort($array_listado);
    return $array_listado;
}
开发者ID:BackupTheBerlios,项目名称:baifox-svn,代码行数:28,代码来源:include_funciones.php

示例9: findField

 /**
  * @param string $name
  *
  * @throws ElementNotFoundException
  *
  * @return NodeElement
  */
 public function findField($name)
 {
     $currency = null;
     if (1 === preg_match('/in (.{1,3})$/', $name)) {
         // Price in EUR
         list($name, $currency) = explode(' in ', $name);
         return $this->findPriceField($name, $currency);
     } elseif (1 < str_word_count($name)) {
         // mobile Description
         $words = explode(' ', $name);
         $scope = array_shift($words);
         $name = implode(' ', $words);
         // Check that it is really a scoped field, not a field with a two word label
         if (strtolower($scope) === $scope) {
             return $this->findScopedField($name, $scope);
         }
     }
     $label = $this->find('css', sprintf('label:contains("%s")', $name));
     if (!$label) {
         throw new ElementNotFoundException($this->getSession(), 'form label ', 'value', $name);
     }
     $field = $label->getParent()->find('css', 'input,textarea');
     if (!$field) {
         throw new ElementNotFoundException($this->getSession(), 'form field ', 'id|name|label|value', $name);
     }
     return $field;
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:34,代码来源:Edit.php

示例10: add

 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $accumulatedPoints = array();
     $point = $this->Points->newEntity();
     if ($this->request->is('post')) {
         $point = $this->Points->patchEntity($point, $this->request->data);
         if ($this->Points->save($point)) {
             $this->Flash->success(__('The point has been saved.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The point could not be saved. Please, try again.'));
         }
     }
     $username = $this->Points->Users->find('list', ['keyField' => 'id', 'valueField' => 'name'], ['limit' => 200])->toArray();
     $users = $this->Points->Users->find('all', ['contain' => ['Diarys', 'Historys', 'Points', 'Words', 'CompletedWords']]);
     //make array of most recent accumulated points
     foreach ($users as $user) {
         $sum = 0;
         foreach ($user->diarys as $diary) {
             $sum = $sum + str_word_count($diary['body']) % $this->maxWord * $this->rateJournalWord;
         }
         $numWords = 0;
         foreach ($user->words as $word) {
             if ($word->meaning != null) {
                 $numWords++;
             }
         }
         $accumulatedPoints[$user->id] = $numWords * $this->rateAddWord + count($user->completed_words) * $this->rateFinishWord + count($user->diarys) * $this->rateJournal + count($user->historys) * $this->rateHistory + $sum;
     }
     //make array of most recent remained points
     $remainedPoints = $this->Points->find('list', ['keyField' => 'user_id', 'valueField' => 'remained_points'], ['limit' => 200])->order(['id' => 'ASC'])->toArray();
     $this->set(compact('point', 'accumulatedPoints', 'remainedPoints', 'username'));
 }
开发者ID:infomat,项目名称:wordmaster,代码行数:38,代码来源:PointsController.php

示例11: test

 public function test($target)
 {
     $DOM = $target;
     $page = $DOM->saveHTML();
     $body_elements = $DOM->getElementsByTagName('body');
     $tags = $body_elements->item(0)->childNodes;
     foreach ($tags as $tag) {
         if ($tag->nodeName == "script" || $tag->nodeName == "noscript" || $tag->nodeName == "style") {
             continue;
         }
         if ($tag->nodeName == "p") {
             $this->p_content .= ' ' . $tag->textContent;
         }
         $this->text_content .= $tag->textContent;
     }
     $all_text = $this->text_content;
     $ratio = number_format(strlen($all_text) * 100 / strlen($page), 2);
     $num_words = str_word_count($this->p_content);
     if ($ratio >= 25) {
         $this->result .= '<p><span class="result ok">OK</span>Text / HTML ratio in your website is above 25%.</p><pre>' . $ratio . '% ratio</pre><code>' . $this->text_content . '</code>' . "\n";
         $this->score += 1;
     } else {
         $this->result .= '<p><span class="result warn">WARN</span>Text / HTML ratio in your website is below 25%.</p><pre>' . $ratio . '% ratio</pre><code>' . $this->text_content . '</code>' . "\n";
     }
     if ($num_words >= 300) {
         $this->result .= '<p><span class="result ok">OK</span>Number of words in your text is above 300 words.</p><pre>' . $num_words . ' words</pre><code>' . $this->p_content . '</code>' . "\n";
         $this->score += 1;
     } else {
         $this->result .= '<p><span class="result warn">WARN</span>Number of words in your text is below 300 words.</p><pre>' . $num_words . ' words</pre><code>' . $this->p_content . '</code>' . "\n";
     }
     return array("name" => "textratio", "score" => $this->score, "total_score" => self::TOTAL_SCORE, "result" => $this->result);
 }
开发者ID:fran-diaz,项目名称:itseo,代码行数:32,代码来源:textRatio.php

示例12: appica_widget_trim_excerpt

/**
 * Reduce the length of custom excerpt (if specified manually) for widgets.
 *
 * @param string $excerpt Current excerpt
 *
 * @since 1.0.0
 *
 * @return string
 */
function appica_widget_trim_excerpt($excerpt)
{
    if (false === strpos($excerpt, '...') && str_word_count($excerpt) > 9) {
        $excerpt = wp_trim_words($excerpt, 9, ' ...');
    }
    return $excerpt;
}
开发者ID:narendra-addweb,项目名称:m1,代码行数:16,代码来源:widgets.php

示例13: obtainData

function obtainData($objDb, $id)
{
    $aRes = $objDb->GetDetails($id);
    $sText = $objDb->GetRawText($id);
    if ($aRes === FALSE || $sText === FALSE) {
        // No such record!
        return FALSE;
    }
    // Clean up list of words
    $aWords = array_filter(array_unique(str_word_count($sText, 1)), "filter_words");
    // Split words into likely and unlikely (based on spelling)
    $aLikely = array();
    $aUnlikely = array();
    $hSpell = pspell_new("en");
    if ($hSpell !== FALSE) {
        foreach ($aWords as $sWord) {
            // Make a spellcheck on it
            if (pspell_check($hSpell, $sWord)) {
                array_push($aLikely, $sWord);
            } else {
                array_push($aUnlikely, $sWord);
            }
        }
    } else {
        $aLikely = $aWords;
    }
    return array("likely" => $aLikely, "unlikely" => $aUnlikely);
}
开发者ID:neerumsr,项目名称:lagerdox,代码行数:28,代码来源:create_category.php

示例14: test

 public function test($target)
 {
     $title = self::extractTitle($target);
     $metatitle = self::extractMetaTitle($target);
     if (strlen($metatitle) >= 1) {
         $this->result .= '<p><span class="result ok">OK</span>The meta title is present: <pre>' . $metatitle . '</pre></p>' . "\n";
         $this->score += 1;
         $metatitle_length = str_word_count($metatitle);
         if ($metatitle_length == 9) {
             $this->result .= '<p><span class="result ok">OK</span>Meta title length is good: <pre>9 words</pre></p>' . "\n";
             $this->score += 1;
         } else {
             $this->result .= '<p><span class="result warn">WARN</span>Meta title length should be 9 words, detected: <pre>' . $metatitle_length . ' words</pre></p>' . "\n";
         }
         $metatitle_length = strlen($metatitle);
         if ($metatitle_length >= 60 && $metatitle_length <= 70) {
             $this->result .= '<p><span class="result ok">OK</span>Meta title length is good: <pre>65 characters</pre></p>' . "\n";
             $this->score += 1;
         } else {
             $this->result .= '<p><span class="result warn">WARN</span>Meta title length should between 60 and 70 characters aprox. (included spaces), detected: <pre>' . $metatitle_length . ' characters</pre></p>' . "\n";
         }
         // title == metatitle
         if (strcmp($title, $metatitle) == 0) {
             $this->result .= '<p><span class="result ok">OK</span>Meta title is equal to page title</p>' . "\n";
             $this->score += 1;
         } else {
             $this->result .= '<p><span class="result error">Error</span>Meta title is different to page title: <pre>' . $title . "\n" . $metatitle . '</pre></p>' . "\n";
         }
     } else {
         $this->result .= '<p><span class="result error">ERROR</span>No meta title detected!</p>' . "\n";
         $this->result .= '<p><span class="result error">ERROR</span>Meta title length should be 9 words and 60 - 70 characters, none is detected.</p>' . "\n";
     }
     return array("name" => "metatitle", "score" => $this->score, "total_score" => self::TOTAL_SCORE, "result" => $this->result);
 }
开发者ID:fran-diaz,项目名称:itseo,代码行数:34,代码来源:metaTitle.php

示例15: testTruncatesLongTextToGivenNumberOfWords

 public function testTruncatesLongTextToGivenNumberOfWords()
 {
     $nwords = str_word_count(strip_tags(Truncator::truncate($this->long_text, 10, '')));
     $this->assertEquals(10, $nwords);
     $nwords = str_word_count(strip_tags(Truncator::truncate($this->long_text, 11, '')));
     $this->assertEquals(11, $nwords);
 }
开发者ID:lostcause,项目名称:php-htmltruncator,代码行数:7,代码来源:htmltruncator.test.php


注:本文中的str_word_count函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。