本文整理汇总了PHP中truncate_text函数的典型用法代码示例。如果您正苦于以下问题:PHP truncate_text函数的具体用法?PHP truncate_text怎么用?PHP truncate_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了truncate_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show_message_overview
private function show_message_overview()
{
if (($message_count = $this->model->count_messages()) === false) {
$this->output->add_tag("result", "Database error.");
return false;
}
$paging = new pagination($this->output, "admin_forum", $this->settings->admin_page_size, $message_count);
if (($messages = $this->model->get_messages($paging->offset, $paging->size)) === false) {
$this->output->add_tag("result", "Database error.");
return;
}
$this->output->open_tag("overview");
$this->output->open_tag("messages");
foreach ($messages as $message) {
$message["content"] = truncate_text($message["content"], 400);
$message["timestamp"] = date("j F Y, H:i", $message["timestamp"]);
if ($message["author"] == "") {
$message["author"] = $message["username"];
}
$this->output->record($message, "message");
}
$this->output->close_tag();
$paging->show_browse_links();
$this->output->close_tag();
}
示例2: show_faq_overview
public function show_faq_overview()
{
if (($sections = $this->model->get_all_sections()) === false) {
$this->output->add_tag("result", "Database error.");
return;
} else {
if (($faqs = $this->model->get_all_faqs()) === false) {
$this->output->add_tag("result", "Database error.");
return;
}
}
$this->output->open_tag("overview");
$this->output->open_tag("sections");
foreach ($sections as $section) {
$this->output->add_tag("section", $section["label"], array("id" => $section["id"]));
}
$this->output->close_tag();
$this->output->open_tag("faqs");
foreach ($faqs as $faq) {
$faq["question"] = truncate_text($faq["question"], 140);
$this->output->record($faq, "faq");
}
$this->output->close_tag();
$this->output->close_tag();
}
示例3: execute
public function execute()
{
if ($_SERVER["REQUEST_METHOD"] == "POST") {
/* Delete message
*/
if ($this->model->delete_message($_POST["id"])) {
$this->user->log_action("guestbook entry %d deleted", $_POST["id"]);
}
}
handle_table_sort("adminguestbook_order", array("author", "message", "timestamp", "ip_address"), array("timestamp", "author"));
$paging = new pagination($this->output, "admin_guestbook", $this->settings->admin_page_size, $message_count);
if (($guestbook = $this->model->get_messages($_SESSION["adminguestbook_order"], $paging->offset, $paging->size)) === false) {
$this->output->add_tag("result", "Database error.");
return;
}
$this->output->open_tag("guestbook");
foreach ($guestbook as $item) {
$item["message"] = truncate_text($item["message"], 45);
if ($this->output->mobile) {
$item["timestamp"] = date("Y-m-d", $item["timestamp"]);
} else {
$item["timestamp"] = date("j F Y, H:i", $item["timestamp"]);
}
$this->output->record($item, "item");
}
$paging->show_browse_links();
$this->output->close_tag();
}
示例4: extractSummaryArray
public static function extractSummaryArray($body, $min, $total)
{
//replace whitespaces with space
$body = preg_replace("/(\\r?\\n[ \\t]*)+/", " ", $body);
//find paragraphs
$matches = array();
preg_match_all("/<p>(.+)<\\/p>/isU", $body, $matches, PREG_SET_ORDER);
//put paragraphs to a fresh array and calculate total length
$total_length = 0;
$paragraphs = array();
foreach ($matches as $match) {
$len = 0;
if (($len = strlen($match[1])) > $min) {
$paragraphs[] = $match[1];
$total_length += strlen($match[1]);
}
}
//chop paragraphs
sfLoader::loadHelpers('Text');
$final = array();
for ($i = 0; $i < sizeof($paragraphs); $i++) {
$share = (int) ($total * strlen($paragraphs[$i]) / $total_length);
if ($share < $min) {
$total_length -= strlen($paragraphs[$i]);
continue;
}
$final[] = truncate_text($paragraphs[$i], $share, "", true);
}
return $final;
}
示例5: truncate_description
function truncate_description($description, $route, $length = 500, $has_abstract = false)
{
if ($has_abstract) {
$description = extract_abstract($description);
}
$more = '... <span class="more_text">' . link_to('[' . __('Read more') . ']', $route) . '</span>';
return parse_links(parse_bbcode_simple(truncate_text($description, $length, $more)));
}
示例6: execute
public function execute()
{
if ($this->user->logged_in == false) {
unset($this->sections["mail"]);
}
if (isset($_SESSION["search"]) == false) {
$_SESSION["search"] = array();
foreach ($this->sections as $section => $label) {
$_SESSION["search"][$section] = true;
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->log_search_query($_POST["query"]);
foreach ($this->sections as $section => $label) {
$_SESSION["search"][$section] = is_true($_POST[$section]);
}
}
$this->output->add_css("banshee/js_pagination.css");
$this->output->add_javascript("banshee/pagination.js");
$this->output->add_javascript("search.js");
$this->output->run_javascript("document.getElementById('query').focus()");
$this->output->add_tag("query", $_POST["query"]);
$this->output->open_tag("sections");
foreach ($this->sections as $section => $label) {
$params = array("label" => $label, "checked" => show_boolean($_SESSION["search"][$section]));
$this->output->add_tag("section", $section, $params);
}
$this->output->close_tag();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (strlen(trim($_POST["query"])) < 3) {
$this->output->add_tag("result", "Search query too short.");
} else {
if (($result = $this->model->search($_POST, $this->sections)) === false) {
/* Error
*/
$this->output->add_tag("result", "Search error.");
} else {
if (count($result) == 0) {
$this->output->add_tag("result", "No matches found.");
} else {
/* Results
*/
foreach ($result as $section => $hits) {
$this->output->open_tag("section", array("section" => $section, "label" => $this->sections[$section]));
foreach ($hits as $hit) {
$hit["text"] = strip_tags($hit["text"]);
$hit["content"] = strip_tags($hit["content"]);
$hit["content"] = preg_replace('/\\[.*?\\]/', "", $hit["content"]);
$hit["content"] = truncate_text($hit["content"], 400);
$this->output->record($hit, "hit");
}
$this->output->close_tag();
}
}
}
}
}
}
示例7: link_to_related_property
/**
* creates a link to related schema property
*
* @return none
* @param schemaproperty $property
*/
function link_to_related_property($property)
{
$relPropertyId = $property->getIsSubpropertyOf();
$relPropertyUri = $property->getParentUri();
if ($relPropertyId) {
//get the related concept
$relProperty = SchemaPropertyPeer::retrieveByPK($relPropertyId);
if ($relProperty) {
return link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relPropertyId, ['title' => $relPropertyUri]);
}
}
//if all else fails we display a truncated = 30 value
return truncate_text($property->getParentUri(), 30);
}
示例8: show_mails
private function show_mails($mails, $column)
{
$this->output->open_tag("mailbox", array("column" => $column));
foreach ($mails as $mail) {
$mail["subject"] = truncate_text($mail["subject"], 55);
if ($this->mobile) {
$mail["timestamp"] = date_string("Y-m-d", $mail["timestamp"]);
} else {
$mail["timestamp"] = date_string("l, j F Y H:i:s", $mail["timestamp"]);
}
$mail["read"] = $mail["read"] == YES ? "read" : "unread";
$this->output->record($mail, "mail");
}
$this->output->close_tag();
}
示例9: generateMessage
/**
* generate Wildcard.. truncate if necessary, $pUrl is optional
*
* @param YiidActivity $pActivity
* @return string
*/
public function generateMessage($pActivity)
{
sfProjectConfiguration::getActive()->loadHelpers('Text');
$lUrl = ShortUrlTable::shortenUrl($pActivity->generateUrlWithClickbackParam($this->onlineIdentity));
$lMaxChars = 135;
$lText = $lUrl;
$lLengthOfText = strlen($lText);
if ($pActivity->getComment()) {
$lChars = $lMaxChars - $lLengthOfText;
$lText = truncate_text($pActivity->getComment(), $lChars, '...') . " " . $lText;
} elseif ($pActivity->getTitle()) {
$lChars = $lMaxChars - $lLengthOfText;
$lText = truncate_text($pActivity->getTitle(), $lChars, '...') . " " . $lText;
}
return array("status" => $lText);
}
示例10: link_to_related
/**
* creates a link to related concept
*
* @return none
* @param conceptproperty $property
*/
function link_to_related($property)
{
$relConceptId = $property->getRelatedConceptId();
if ($relConceptId) {
//get the related concept
$relConcept = ConceptPeer::retrieveByPK($relConceptId);
if ($relConcept) {
return link_to($relConcept->getPrefLabel(), 'concept/show/?id=' . $relConceptId);
}
}
//If the skosProperty.objectType is resource then we display a truncated URI with a complete link_to
if ($property->getProfileProperty()->getIsObjectProp()) {
return link_to(truncate_text($property->getObject(), 30), $property->getObject());
}
//if all else fails we display a truncated = 30 value
return truncate_text($property->getObject(), 30);
}
示例11: summarize
public function summarize($body)
{
$matches = array();
preg_match_all("/<p>(.+)<\\/p>/isU", $body, $matches, PREG_SET_ORDER);
$paragraphs = array();
foreach ($matches as $match) {
$paragraphs[] = preg_replace("/(\\r?\\n[ \\t]*)+/", " ", strip_tags($match[1]));
}
$total = $this->total($paragraphs);
foreach ($paragraphs as $i => $paragraph) {
if (strlen($paragraph) / $total * 100 < $this->threshold) {
unset($paragraphs[$i]);
}
}
$total = $this->total($paragraphs);
$spaces = count($paragraphs) - 1;
foreach ($paragraphs as $i => $paragraph) {
$paragraphs[$i] = truncate_text($paragraph, strlen($paragraph) / $total * ($this->max - $spaces), '...', true);
}
return implode(' ', $paragraphs);
}
示例12: show_weblog_form
private function show_weblog_form($weblog)
{
$this->output->add_javascript("ckeditor/ckeditor.js");
$this->output->add_javascript("banshee/start_ckeditor.js");
$this->output->open_tag("edit");
$weblog["visible"] = show_boolean($weblog["visible"]);
$this->output->record($weblog, "weblog");
/* Tags
*/
$tagged = array();
if (isset($weblog["tag"])) {
$tagged = $weblog["tag"];
} else {
if (($weblog_tags = $this->model->get_weblog_tags($weblog["id"])) != false) {
foreach ($weblog_tags as $tag) {
array_push($tagged, $tag["id"]);
}
}
}
$this->output->open_tag("tags");
if (($tags = $this->model->get_tags()) != false) {
foreach ($tags as $tag) {
$this->output->add_tag("tag", $tag["tag"], array("id" => $tag["id"], "selected" => show_boolean(in_array($tag["id"], $tagged))));
}
}
$this->output->close_tag();
/* Comments
*/
$this->output->open_tag("comments");
if (($weblog_comments = $this->model->get_weblog_comments($weblog["id"])) != false) {
foreach ($weblog_comments as $comment) {
$comment["content"] = truncate_text($comment["content"], 100);
$this->output->record($comment, "comment");
}
}
$this->output->close_tag();
$this->output->close_tag();
}
示例13: document_get_field_value
/**
* Функция получения содержимого поля для обработки в шаблоне рубрики
*
* @param int $field_id идентификатор поля, для [tag:fld:12] $field_id = 12
* @param int $length необязательный параметр,
* количество возвращаемых символов содержимого поля.
* если данный параметр указать со знаком минус
* содержимое поля будет очищено от HTML-тегов.
* @return string
*/
function document_get_field_value($field_id, $length = 0)
{
if (!is_numeric($field_id)) {
return '';
}
$document_fields = get_document_fields(get_current_document_id());
$field_value = trim($document_fields[$field_id]['field_value']);
if ($field_value != '') {
$field_value = strip_tags($field_value, "<br /><strong><em><p><i>");
if (is_numeric($length) && $length != 0) {
if ($length < 0) {
$field_value = strip_tags($field_value);
$field_value = preg_replace('/ +/', ' ', $field_value);
$field_value = trim($field_value);
$length = abs($length);
}
$field_value = truncate_text($field_value, $length, '…', true);
}
}
return $field_value;
}
示例14: foreach
</thead>
<tbody>
<?php
foreach ($pager->getResults() as $rt_comment) {
?>
<tr>
<td>
<a href="<?php
echo url_for('rtCommentAdmin/edit?id=' . $rt_comment->getId());
?>
"><?php
echo $rt_comment->getAuthorName();
?>
</a>:<br />
<?php
echo truncate_text(strip_tags($rt_comment->getContent()), 100);
?>
</td>
<td class="rt-admin-publish-toggle">
<?php
echo rt_nice_boolean($rt_comment->getIsActive());
?>
<div style="display:none;"><?php
echo $rt_comment->getId();
?>
</div>
</td>
<td><?php
echo $rt_comment->getCreatedAt();
?>
</td>
示例15: truncate_text
<?php
echo truncate_text($event->getDescription(), 150);