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


PHP count_words函数代码示例

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


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

示例1: add_txt

function add_txt($file, $name, $uid, $textassoc = null, $start = 0, $end = 0)
{
    // open the file
    $filestr = open_file($file);
    // =========== GENERALIZE THIS PLZ =======================================
    // arrayify the text into canonical array form
    $acanon = str_to_array($filestr, "[^a-zA-Z0-9_\\s]");
    // get the hash of the text
    $hash = count_words($acanon);
    // get counts of uniques, hapax, ...
    $counts = get_counts($hash);
    // get a unique text hash to be used as location data
    $thash = file_id($uid, $name, $filestr);
    // must build aarray to send to db add function
    $data['name'] = $name;
    $data['words'] = $hash;
    $data['user'] = $uid;
    $data['counts'] = $counts;
    $data['start'] = $start;
    $data['end'] = $end ? $end : $counts['total'] - 1;
    $data['assoc'] = $textassoc;
    $data['canon'] = $filestr;
    $data['hash'] = $thash;
    // call the add function in MODQUERY and retrive the text_id
    $tid = add_text_to_db($data);
    return $tid;
}
开发者ID:raffled,项目名称:Lexomics,代码行数:27,代码来源:counter.php

示例2: get_string

 }
 if ($entry = get_record('journal_entries', 'userid', $USER->id, 'journal', $journal->id)) {
     if (empty($entry->text)) {
         echo '<p align="center"><b>' . get_string('blankentry', 'journal') . '</b></p>';
     } else {
         echo format_text($entry->text, $entry->format);
     }
 } else {
     echo '<span class="warning">' . get_string('notstarted', 'journal') . '</span>';
 }
 print_simple_box_end();
 if ($timenow < $timefinish) {
     if (!empty($entry->modified)) {
         echo '<div class="lastedit"><strong>' . get_string('lastedited') . ':</strong> ';
         echo userdate($entry->modified);
         echo ' (' . get_string('numwords', '', count_words($entry->text)) . ')';
         echo "</div>";
     }
     if (!empty($journal->days)) {
         echo '<div class="editend"><strong>' . get_string('editingends', 'journal') . ':</strong> ';
         echo userdate($timefinish) . '</div>';
     }
 } else {
     echo '<div class="editend"><strong>' . get_string('editingended', 'journal') . ':</strong> ';
     echo userdate($timefinish) . '</div>';
 }
 if (!empty($entry->entrycomment) or !empty($entry->rating)) {
     $grades = make_grades_menu($journal->assessed);
     print_heading(get_string('feedback'));
     journal_print_feedback($course, $entry, $grades);
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:view.php

示例3: save_review

 function save_review($req, $rrow, $prow, $contact, &$tf = null)
 {
     global $Conf, $Opt;
     $newsubmit = @$req["ready"] && !@$req["unready"] && (!$rrow || !$rrow->reviewSubmitted);
     $submit = $newsubmit || $rrow && $rrow->reviewSubmitted;
     $admin = $contact->allow_administer($prow);
     if (!$contact->timeReview($prow, $rrow) && (!isset($req['override']) || !$admin)) {
         return Conf::msg_error("The <a href='" . hoturl("deadlines") . "'>deadline</a> for entering this review has passed." . ($admin ? "  Select the “Override deadlines” checkbox and try again if you really want to override the deadline." : ""));
     }
     $q = array();
     $diff_view_score = VIEWSCORE_FALSE;
     $wc = 0;
     foreach ($this->forder as $field => $f) {
         if (isset($req[$field]) && (!$f->round_mask || $f->is_round_visible($rrow))) {
             $fval = $req[$field];
             if ($f->has_options) {
                 if ($f->parse_is_empty($fval)) {
                     $fval = 0;
                 } else {
                     if (!($fval = $f->parse_value($fval, false))) {
                         continue;
                     }
                 }
             } else {
                 $fval = rtrim($fval);
                 if ($fval != "") {
                     $fval .= "\n";
                 }
                 // Check for valid UTF-8; re-encode from Windows-1252 or Mac OS
                 $fval = convert_to_utf8($fval);
                 if ($f->include_word_count()) {
                     $wc += count_words($fval);
                 }
             }
             if ($rrow && strcmp($rrow->{$field}, $fval) != 0 && strcmp(cleannl($rrow->{$field}), cleannl($fval)) != 0) {
                 $diff_view_score = max($diff_view_score, $f->view_score);
             }
             $q[] = "{$field}='" . sqlq($fval) . "'";
         }
     }
     // get the current time
     $now = time();
     if ($rrow && $rrow->reviewModified && $rrow->reviewModified > $now) {
         $now = $rrow->reviewModified + 1;
     }
     // potentially assign review ordinal (requires table locking since
     // mySQL is stupid)
     $locked = false;
     if ($newsubmit) {
         $diff_view_score = max($diff_view_score, VIEWSCORE_AUTHOR);
         $q[] = "reviewSubmitted={$now}, reviewNeedsSubmit=0";
         if (!$rrow || !$rrow->reviewOrdinal) {
             $result = $Conf->qe("lock tables PaperReview write");
             if (!$result) {
                 return $result;
             }
             $locked = true;
             $result = $Conf->qe("select coalesce(max(reviewOrdinal), 0) from PaperReview where paperId={$prow->paperId} group by paperId");
             if ($result) {
                 $crow = edb_row($result);
                 $q[] = "reviewOrdinal=coalesce(reviewOrdinal, " . ($crow[0] + 1) . ")";
             }
             Dbl::free($result);
             $q[] = "timeDisplayed={$now}";
         }
     }
     // check whether used a review token
     $usedReviewToken = $contact->review_token_cid($prow, $rrow);
     // blind? reviewer type? edit version?
     $reviewBlind = $Conf->is_review_blind(!!@$req["blind"]);
     if ($rrow && $reviewBlind != $rrow->reviewBlind) {
         $diff_view_score = max($diff_view_score, VIEWSCORE_ADMINONLY);
     }
     $q[] = "reviewBlind=" . ($reviewBlind ? 1 : 0);
     if ($rrow && $rrow->reviewType == REVIEW_EXTERNAL && $contact->contactId == $rrow->contactId && $contact->isPC && !$usedReviewToken) {
         $q[] = "reviewType=" . REVIEW_PC;
     }
     if ($rrow && $diff_view_score > VIEWSCORE_FALSE && isset($req["version"]) && ctype_digit($req["version"]) && $req["version"] > defval($rrow, "reviewEditVersion")) {
         $q[] = "reviewEditVersion=" . ($req["version"] + 0);
     }
     if ($diff_view_score > VIEWSCORE_FALSE && $Conf->sversion >= 98) {
         $q[] = "reviewWordCount=" . $wc;
     }
     if (isset($req["reviewFormat"]) && $Conf->sversion >= 104 && @$Opt["formatInfo"]) {
         $fmt = null;
         foreach ($Opt["formatInfo"] as $k => $f) {
             if (@$f["name"] && strcasecmp($f["name"], $req["reviewFormat"]) == 0) {
                 $fmt = (int) $k;
             }
         }
         if (!$fmt && $req["reviewFormat"] && preg_match('/\\A(?:plain\\s*)?(?:text)?\\z/i', $f["reviewFormat"])) {
             $fmt = 0;
         }
         $q[] = "reviewFormat=" . ($fmt === null ? "null" : $fmt);
     }
     // notification
     $notification_bound = $now - 10800;
     $notify = $notify_author = false;
     if (!$rrow || $diff_view_score > VIEWSCORE_FALSE) {
         $q[] = "reviewModified=" . $now;
//.........这里部分代码省略.........
开发者ID:vaskevich,项目名称:nu-admissions-review,代码行数:101,代码来源:review.php

示例4: forum_print_post


//.........这里部分代码省略.........
    $output .= html_writer::div($bytext, 'author', $bytextoptions);
    // End topic column.
    $output .= html_writer::end_div();
    // End header row.
    $output .= html_writer::end_div();
    // Row with the forum post content.
    $output .= html_writer::start_div('row maincontent clearfix');
    // Show if author is not hidden or we have groups.
    if (!$authorhidden || $groups) {
        $output .= html_writer::start_div('left');
        $groupoutput = '';
        if ($groups) {
            $groupoutput = print_group_picture($groups, $course->id, false, true, true);
        }
        if (empty($groupoutput)) {
            $groupoutput = '&nbsp;';
        }
        $output .= html_writer::div($groupoutput, 'grouppictures');
        $output .= html_writer::end_div();
        // Left side.
    }
    $output .= html_writer::start_tag('div', array('class' => 'no-overflow'));
    $output .= html_writer::start_tag('div', array('class' => 'content'));
    $options = new stdClass();
    $options->para = false;
    $options->trusted = $post->messagetrust;
    $options->context = $modcontext;
    if ($shortenpost) {
        // Prepare shortened version by filtering the text then shortening it.
        $postclass = 'shortenedpost';
        $postcontent = format_text($post->message, $post->messageformat, $options);
        $postcontent = shorten_text($postcontent, $CFG->forum_shortpost);
        $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
        $postcontent .= html_writer::tag('div', '(' . get_string('numwords', 'moodle', count_words($post->message)) . ')', array('class' => 'post-word-count'));
    } else {
        // Prepare whole post
        $postclass = 'fullpost';
        $postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
        if (!empty($highlight)) {
            $postcontent = highlight($highlight, $postcontent);
        }
        if (!empty($forum->displaywordcount)) {
            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), array('class' => 'post-word-count'));
        }
        $postcontent .= html_writer::tag('div', $attachedimages, array('class' => 'attachedimages'));
    }
    // Output the post content
    $output .= html_writer::tag('div', $postcontent, array('class' => 'posting ' . $postclass));
    $output .= html_writer::end_tag('div');
    // Content
    $output .= html_writer::end_tag('div');
    // Content mask
    $output .= html_writer::end_tag('div');
    // Row
    $output .= html_writer::start_tag('div', array('class' => 'row side'));
    $output .= html_writer::tag('div', '&nbsp;', array('class' => 'left'));
    $output .= html_writer::start_tag('div', array('class' => 'options clearfix'));
    if (!empty($attachments)) {
        $output .= html_writer::tag('div', $attachments, array('class' => 'attachments'));
    }
    // Output ratings
    if (!empty($post->rating)) {
        $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class' => 'forum-post-rating'));
    }
    // Output the commands
    $commandhtml = array();
开发者ID:rezaies,项目名称:moodle,代码行数:67,代码来源:lib.php

示例5: print_error

}
if ($assignment->assignmenttype != 'online') {
    print_error('invalidtype', 'assignment');
}
$assignmentinstance = new assignment_online($cm->id, $assignment, $cm, $course);
if ($submission = $assignmentinstance->get_submission($user->id)) {
    print_header(fullname($user, true) . ': ' . $assignment->name);
    echo $OUTPUT->box_start('generalbox boxaligcenter', 'dates');
    echo '<table>';
    if ($assignment->timedue) {
        echo '<tr><td class="c0">' . get_string('duedate', 'assignment') . ':</td>';
        echo '    <td class="c1">' . userdate($assignment->timedue) . '</td></tr>';
    }
    echo '<tr><td class="c0">' . get_string('lastedited') . ':</td>';
    echo '    <td class="c1">' . userdate($submission->timemodified);
    /// Decide what to count
    if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
        echo ' (' . get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))) . ')</td></tr>';
    } else {
        if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
            echo ' (' . get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))) . ')</td></tr>';
        }
    }
    echo '</table>';
    echo $OUTPUT->box_end();
    echo $OUTPUT->box(format_text($submission->data1, $submission->data2), 'generalbox boxaligncenter boxwidthwide');
    echo $OUTPUT->close_window_button();
    echo $OUTPUT->footer();
} else {
    print_string('emptysubmission', 'assignment');
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:file.php

示例6: test_count_words

 /**
  * Test function count_words().
  */
 public function test_count_words()
 {
     $count = count_words("one two three'four");
     $this->assertEquals(3, $count);
     $count = count_words('one+two three’four');
     $this->assertEquals(3, $count);
     $count = count_words('one"two three-four');
     $this->assertEquals(3, $count);
     $count = count_words('one@two three_four');
     $this->assertEquals(4, $count);
     $count = count_words('one\\two three/four');
     $this->assertEquals(4, $count);
     $count = count_words(' one ... two &nbsp; three...four ');
     $this->assertEquals(4, $count);
     $count = count_words('one.2 3,four');
     $this->assertEquals(4, $count);
     $count = count_words('1³ £2 €3.45 $6,789');
     $this->assertEquals(4, $count);
     $count = count_words('one—two ブルース カンベッル');
     $this->assertEquals(4, $count);
     $count = count_words('one…two ブルース … カンベッル');
     $this->assertEquals(4, $count);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:26,代码来源:moodlelib_test.php

示例7: the_ID

</p>
        <h3><a data-id="<?php 
the_ID();
?>
" class="posttitle" href="<?php 
the_permalink();
?>
"><?php 
the_title();
?>
</a></h3>
        <p><?php 
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 100, "...");
?>
</p>
        <p class="here">
            <span class="icon-letter"><?php 
echo count_words($text);
?>
</span>
            <span class="icon-view"><?php 
echo getPostViews(get_the_ID());
?>
</span>
            <?php 
tz_printLikes(get_the_ID());
?>
        </p>
    </div>
</div>
开发者ID:J3n5en,项目名称:Diaspora,代码行数:30,代码来源:post.php

示例8: format_for_log

 /**
  * Formatting for log info
  *
  * @param stdClass $submission The new submission
  * @return string
  */
 public function format_for_log(stdClass $submission)
 {
     // format the info for each submission plugin add_to_log
     $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
     $onlinetextloginfo = '';
     $text = format_text($onlinetextsubmission->onlinetext, $onlinetextsubmission->onlineformat, array('context' => $this->assignment->get_context()));
     $onlinetextloginfo .= get_string('numwordsforlog', 'assignsubmission_onlinetext', count_words($text));
     return $onlinetextloginfo;
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:15,代码来源:locallib.php

示例9: chunker

 private function chunker(&$text, $style = "")
 {
     $errors = null;
     $text = collapse_spaces($text);
     $textarr = split_string($text);
     $chunksarr = split_on_spaces($textarr, $this->spaces);
     if ($style == "clean") {
         $chunksarr = remove_junk($chunksarr);
     }
     $chunkhashes = null;
     foreach ($chunksarr as $end => &$chunkarr) {
         $chunkhashes[$end] = count_words($chunkarr);
     }
     if (!$chunkhashes) {
         $errors[] = "Could not hash chunks. Huh.";
         trigger_error("Could not hash chunks. Huh.");
         return $errors;
     }
     // if cleaned style, remove all bad words and lc
     $max = array_pop(array_keys($textarr)) + 1;
     $maxlen = strlen("{$max}");
     $pad = "%0{$maxlen}s";
     foreach ($chunksarr as $end => $chunkarr) {
         $endpad = $end + 1;
         $endpad = sprintf($pad, $endpad);
         $out = $this->write_txt($chunkarr, $endpad, $style);
         $out2 = $this->write_csv($chunkhashes[$end], $endpad, $style);
         if ($out || $out2) {
             $errors = array_merge($out, $out2, $errors);
         }
     }
     if ($errors) {
         rrmdir($this->folder);
         trigger_error("Something in the chunking process went wrong.");
     }
     return $errors;
 }
开发者ID:raffled,项目名称:Lexomics,代码行数:37,代码来源:chunkset.php

示例10: require_login

}
require_login($course->id, false, $cm);
if ($USER->id != $user->id && !has_capability('mod/problemstatement:grade', get_context_instance(CONTEXT_MODULE, $cm->id))) {
    error("You can not view this problemstatement");
}
$problemstatementinstance = new problemstatement($cm->id, $problemstatement, $cm, $course);
if ($submission = $problemstatementinstance->get_submission($user->id)) {
    print_header(fullname($user, true) . ': ' . $problemstatement->name);
    print_simple_box_start('center', '', '', '', 'generalbox', 'dates');
    echo '<table>';
    if ($problemstatement->timedue) {
        echo '<tr><td class="c0">' . get_string('duedate', 'problemstatement') . ':</td>';
        echo '    <td class="c1">' . userdate($problemstatement->timedue) . '</td></tr>';
    }
    echo '<tr><td class="c0">' . get_string('lastedited') . ':</td>';
    echo '    <td class="c1">' . userdate($submission->timemodified);
    /// Decide what to count
    //if ($CFG->problemstatement_itemstocount == ASSIGNMENT_COUNT_WORDS) {
    echo ' (' . get_string('numwords', '', count_words($submission->programtext)) . ')</td></tr>';
    //} else if ($CFG->problemstatement_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
    echo ' (' . get_string('numletters', '', count_letters($submission->programtext)) . ')</td></tr>';
    //}
    echo '</table>';
    print_simple_box_end();
    print_simple_box(highlight_syntax($submission->programtext, $submission->langid), 'center', '100%');
    print_simple_box(format_text($submission->submissioncomment, 0), 'center', '100%');
    close_window_button();
    print_footer('none');
} else {
    print_string('emptysubmission', 'problemstatement');
}
开发者ID:Anna-Sentyakova,项目名称:runningcat,代码行数:31,代码来源:file.php

示例11: post_message

 /**
  * @param stdClass $post
  * @param stdClass $cm
  * @return string
  * @author Mark Nielsen
  */
 public function post_message($post, $cm, $search = '')
 {
     $options = new stdClass();
     $options->para = false;
     $options->trusted = $post->messagetrust;
     $options->context = context_module::instance($cm->id);
     list($attachments, $attachedimages) = hsuforum_print_attachments($post, $cm, 'separateimages');
     $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', context_module::instance($cm->id)->id, 'mod_hsuforum', 'post', $post->id);
     $postcontent = format_text($message, $post->messageformat, $options, $cm->course);
     if (!empty($search)) {
         $postcontent = highlight($search, $postcontent);
     }
     if (!empty($attachments)) {
         $postcontent .= "<div class='attachments'>" . $attachments . "</div>";
     }
     if (!empty($attachedimages)) {
         $postcontent .= "<div class='attachedimages'>" . $attachedimages . "</div>";
     }
     $forum = hsuforum_get_cm_forum($cm);
     if (!empty($forum->displaywordcount)) {
         $postcontent .= "<div class='post-word-count'>" . get_string('numwords', 'moodle', count_words($post->message)) . "</div>";
     }
     $postcontent = "<div class='posting'>" . $postcontent . "</div>";
     return $postcontent;
 }
开发者ID:cdsmith-umn,项目名称:moodle-mod_hsuforum,代码行数:31,代码来源:renderer.php

示例12: comment_form_input_text

		<?php 
    echo comment_form_input_text();
    ?>
</label></p>
		
		<p><?php 
    echo comment_form_button();
    ?>
</p>
	</form>
</section>

<?php 
}
?>

<section class="footnote">
	<p>This article is my <?php 
echo numeral(article_id() + 1);
?>
 oldest. It is <?php 
echo count_words(article_html());
?>
 words long. 
	<?php 
echo article_custom_field('attribution');
?>
</p>
</section>

开发者ID:rubenvincenten,项目名称:anchor-site,代码行数:29,代码来源:article.php

示例13: print_user_files

 function print_user_files($userid, $return = false)
 {
     global $OUTPUT;
     if (!($submission = $this->get_submission($userid))) {
         return '';
     }
     $link = html_link::make("/mod/assignment/type/online/file.php?id={$this->cm}->id&userid={$submission->userid}", shorten_text(trim(strip_tags(format_text($submission->data1, $submission->data2))), 15));
     $link->add_action(new popup_action('click', $link->url, 'file' . $userid, array('height' => 450, 'width' => 580)));
     $link->title = get_string('submission', 'assignment');
     $popup = $OUTPUT->link($link);
     $output = '<div class="files">' . '<img align="middle" src="' . $OUTPUT->old_icon_url('f/html') . '" height="16" width="16" alt="html" />' . $popup . '</div>';
     ///Stolen code from file.php
     echo $OUTPUT->box_start('generalbox boxaligncenter', 'wordcount');
     /// Decide what to count
     if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
         echo ' (' . get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))) . ')';
     } else {
         if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
             echo ' (' . get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))) . ')';
         }
     }
     echo $OUTPUT->box_end();
     echo $OUTPUT->box(format_text($submission->data1, $submission->data2), 'generalbox boxaligncenter boxwidthwide');
     ///End of stolen code from file.php
     if ($return) {
         //return $output;
     }
     //echo $output;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:29,代码来源:assignment.class.php

示例14: count_words

<?php

function count_words($content)
{
    $word = str_word_count($content, 1);
    return $word;
}
$content = file_get_contents('/var/www/test1.txt');
$words = count_words($content);
$result = array_count_values($words);
ksort($result);
//echo $content;
echo "<pre>";
print_r($result);
echo "</pre>";
//$name = $_get['input_name'];
//$fp = @fopen(dirname(__file__).'/'.$name, 'rb');
// $fp = @fopen('/var/www/test1.txt', 'rb');
// if (!$fp) {
//  echo '1111111111';
//  exit;
// }
// while (!feof($fp)) {
//  $content = fgets($fp);
//  echo $content.'<br />';
// }
// fclose($fp);
?>

开发者ID:jerryayanami,项目名称:yangxuan,代码行数:28,代码来源:test1.php

示例15: check_word_count

 /**
  * Compare word count of onlinetext submission to word limit, and return result.
  *
  * @param string $submissiontext Onlinetext submission text from editor
  * @return string Error message if limit is enabled and exceeded, otherwise null
  */
 public function check_word_count($submissiontext)
 {
     global $OUTPUT;
     $wordlimitenabled = $this->get_config('wordlimitenabled');
     $wordlimit = $this->get_config('wordlimit');
     if ($wordlimitenabled == 0) {
         return null;
     }
     // Count words and compare to limit.
     $wordcount = count_words($submissiontext);
     if ($wordcount <= $wordlimit) {
         return null;
     } else {
         $errormsg = get_string('wordlimitexceeded', 'assignsubmission_onlinetext', array('limit' => $wordlimit, 'count' => $wordcount));
         return $OUTPUT->error_text($errormsg);
     }
 }
开发者ID:qanuj,项目名称:moodle,代码行数:23,代码来源:locallib.php


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