本文整理汇总了PHP中truncate函数的典型用法代码示例。如果您正苦于以下问题:PHP truncate函数的具体用法?PHP truncate怎么用?PHP truncate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了truncate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display
public function display()
{
$strTag = utf8_strtolower($this->patharray[0]);
if (!strlen($strTag)) {
redirect($this->controller_path_plain . $this->SID);
}
$arrArticleIDs = $this->pdh->get('articles', 'articles_for_tag', array($strTag));
$arrArticleIDs = $this->pdh->sort($arrArticleIDs, 'articles', 'date', 'desc');
$intStart = $this->in->get('start', 0);
$arrLimitedIDs = $this->pdh->limit($arrArticleIDs, $intStart, $this->user->data['user_nlimit']);
//Articles to template
foreach ($arrLimitedIDs as $intArticleID) {
$userlink = '<a href="' . $this->routing->build('user', $this->pdh->geth('articles', 'user_id', array($intArticleID)), 'u' . $this->pdh->get('articles', 'user_id', array($intArticleID))) . '">' . $this->pdh->geth('articles', 'user_id', array($intArticleID)) . '</a>';
//Content dependet from list_type
//1 = until readmore
//2 = Headlines only
//3 = only first 600 characters
$strText = $this->pdh->get('articles', 'text', array($intArticleID));
$arrContent = preg_split('#<hr(.*)id="system-readmore"(.*)\\/>#iU', xhtml_entity_decode($strText));
$strText = $this->bbcode->parse_shorttags($arrContent[0]);
$strPath = $this->pdh->get('articles', 'path', array($intArticleID));
$intCategoryID = $this->pdh->get('articles', 'category', array($intArticleID));
//Replace Image Gallery
$arrGalleryObjects = array();
preg_match_all('#<p(.*)class="system-gallery"(.*) data-sort="(.*)" data-folder="(.*)">(.*)</p>#iU', $strText, $arrGalleryObjects, PREG_PATTERN_ORDER);
if (count($arrGalleryObjects[0])) {
include_once $this->root_path . 'core/gallery.class.php';
foreach ($arrGalleryObjects[4] as $key => $val) {
$objGallery = registry::register('gallery');
$strGalleryContent = $objGallery->create($val, (int) $arrGalleryObjects[3][$key], $this->server_path . $strPath, 1);
$strText = str_replace($arrGalleryObjects[0][$key], $strGalleryContent, $strText);
}
}
//Replace Raidloot
$arrRaidlootObjects = array();
preg_match_all('#<p(.*)class="system-raidloot"(.*) data-id="(.*)"(.*) data-chars="(.*)">(.*)</p>#iU', $strText, $arrRaidlootObjects, PREG_PATTERN_ORDER);
if (count($arrRaidlootObjects[0])) {
include_once $this->root_path . 'core/gallery.class.php';
foreach ($arrRaidlootObjects[3] as $key => $val) {
$objGallery = registry::register('gallery');
$withChars = $arrRaidlootObjects[5][$key] == "true" ? true : false;
$strRaidlootContent = $objGallery->raidloot((int) $val, $withChars);
$strText = str_replace($arrRaidlootObjects[0][$key], $strRaidlootContent, $strText);
}
}
$this->comments->SetVars(array('attach_id' => $intArticleID, 'page' => 'articles'));
$intCommentsCount = $this->comments->Count();
//Tags
$arrTags = $this->pdh->get('articles', 'tags', array($intArticleID));
$this->tpl->assign_block_vars('article_row', array('ARTICLE_CONTENT' => $strText, 'ARTICLE_TITLE' => $this->pdh->get('articles', 'title', array($intArticleID)), 'ARTICLE_SUBMITTED' => sprintf($this->user->lang('news_submitter'), $userlink, $this->time->user_date($this->pdh->get('articles', 'date', array($intArticleID)), false, true)), 'ARTICLE_DATE' => $this->time->user_date($this->pdh->get('articles', 'date', array($intArticleID)), false, false, true), 'ARTICLE_PATH' => $this->controller_path . $this->pdh->get('articles', 'path', array($intArticleID)), 'ARTICLE_SOCIAL_BUTTONS' => $arrCategory['social_share_buttons'] ? $this->social->createSocialButtons($this->env->link . $this->pdh->get('articles', 'path', array($intArticleID)), strip_tags($this->pdh->get('articles', 'title', array($intArticleID)))) : '', 'PERMALINK' => $this->pdh->get('articles', 'permalink', array($intArticleID)), 'S_TAGS' => count($arrTags) && $arrTags[0] != "" ? true : false, 'ARTICLE_CUTTED_CONTENT' => truncate($strText, 600, '...', false, true), 'S_READMORE' => isset($arrContent[1]) ? true : false, 'COMMENTS_COUNTER' => $intCommentsCount == 1 ? $intCommentsCount . ' ' . $this->user->lang('comment') : $intCommentsCount . ' ' . $this->user->lang('comments'), 'S_COMMENTS' => $this->pdh->get('articles', 'comments', array($intArticleID)) ? true : false, 'S_FEATURED' => $this->pdh->get('articles', 'featured', array($intArticleID))));
if (count($arrTags) && $arrTags[0] != "") {
foreach ($arrTags as $tag) {
$this->tpl->assign_block_vars('article_row.tag_row', array('TAG' => $tag, 'U_TAG' => $this->routing->build('tag', $tag)));
}
}
}
$this->tpl->assign_vars(array('TAG' => sanitize($strTag), 'PAGINATION' => generate_pagination($this->strPath . $this->SID, count($arrArticleIDs), $this->user->data['user_nlimit'], $intStart, 'start')));
$this->tpl->add_meta('<link rel="canonical" href="' . $this->env->link . $this->routing->build('tag', $tag, false, false, true) . '" />');
$this->core->set_vars(array('page_title' => $this->user->lang("tag") . ': ' . sanitize($strTag), 'template_file' => 'tag.html', 'display' => true));
}
示例2: altText
function altText($text)
{
if (strlen($text) > 100) {
$text = truncate($text, 100);
}
return str_replace("<br />", "\n", str_replace("'", "'", str_replace("\"", """, charReplace($text))));
}
示例3: __construct
public function __construct()
{
gateKeeper();
$guid = getInput("guid");
$title = getInput("blog_title");
$description = getInput("description");
$access_id = getInput("access_id");
$container_guid = getInput("container_guid");
$owner_guid = getLoggedInUserGuid();
if ($guid) {
$blog = getEntity($guid);
} else {
$blog = new Blog();
}
$blog->title = $title;
$blog->description = $description;
$blog->access_id = $access_id;
$blog->owner_guid = $owner_guid;
$blog->status = "published";
$blog->container_guid = $container_guid;
$blog->save();
new Activity(getLoggedInUserGuid(), "blog:add", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $blog->getURL(), $blog->title, truncate($blog->description)), "", $access_id);
new SystemMessage("Your blog has been published");
forward("blogs/all_blogs");
}
示例4: generateMetaDescription
protected function generateMetaDescription()
{
sfProjectConfiguration::getActive()->loadHelpers('StringFunc');
$result = '';
switch ($this->getCurrentPageType()) {
case self::ARTICLE_PAGE:
//pealkiri. Sisu (250 chars)
if ($this->getRoute()->getObject()->getMetadescription()) {
return $this->getRoute()->getObject()->getMetadescription();
}
$content = truncate(strip_tags($this->getRoute()->getObject()->getTitle() . '. ' . $this->getRoute()->getObject()->getContent()), 250, '');
break;
case self::CATEGORY_PAGE:
// category name, products
if ($this->getRoute()->getCategoryObject()->getMetaDescription()) {
return $this->getRoute()->getCategoryObject()->getMetaDescription();
}
$content = implode(',', $this->getProductCategoryPageWords($this->getRoute()->getCategoryObject()));
break;
case self::PRODUCT_PAGE:
//toote nimi (kategooriad) - toode kirjelduse esimesed tähemärgid
$content = $this->getRoute()->getProductObject()->getName() . ' (' . implode(', ', $this->getProductCategoryPageWords($this->getRoute()->getCategoryObject())) . ') ' . $this->getRoute()->getProductObject()->getDescription();
break;
}
$result = truncate(strip_tags($content), 250, '');
return $result;
}
示例5: main_form
function main_form($x, $y, $data)
{
global $pdf;
global $_TITLE, $_LMARGIN, $_BMARGIN;
$balance = $data['balance'] < 0 ? -$data['balance'] : $data['balance'];
$font_size = 14;
$lineh = 25;
$x += $_LMARGIN;
$y += $_BMARGIN;
$y += 275;
$pdf->addtext($x, $y, $font_size, $data['d_name']);
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, trim($data['d_zip'] . ' ' . $data['d_city'] . ' ' . $data['d_address']));
$y -= $lineh;
// for($i=0; $i<26; $i++)
// {
// $pdf->addtext($x+$i*14.6,$y,$font_size,$_ACCOUNT[$i]);
// }
$pdf->addtext($x, $y, $font_size, bankaccount($data['id'], $data['account']));
$y -= $lineh;
$pdf->addtext($x + 220, $y, $font_size, sprintf('%.2f', $balance));
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, trans('$a dollars $b cents', to_words(floor($balance)), to_words(round(($balance - floor($balance)) * 100))));
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, truncate($data['customername']));
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, truncate(trim($data['zip'] . ' ' . $data['city'] . ' ' . $data['address'])));
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, $_TITLE);
$y -= $lineh;
$pdf->addtext($x, $y, $font_size, trans('Customer ID: $a', sprintf('%04d', $data['id'])));
}
示例6: urlize
static function urlize($url, $truncate = false)
{
if (preg_match('/^(http|https|ftp:\\/\\/([^\\s"\']+))/i', $url, $match)) {
$url = "<a href='{$url}'>" . ($truncate ? truncate($url, $truncate) : $url) . '</a>';
}
return $url;
}
示例7: getContentArticle
function getContentArticle($article, $wordwrap = 0)
{
if ($wordwrap > 0) {
$content = strip_tags($article->content);
return truncate($content, $wordwrap, '...');
} else {
return $article->content;
}
}
示例8: __NLStreamCopy
function __NLStreamCopy(NLStream $in, NLStream $out)
{
truncate($out, 0);
fseek($in->_imp_data, 0, SEEK_SET);
fseek($out->_imp_data, 0, SEEK_SET);
$len = __NLStreamCopyAtOffset($in->_imp_data, $out->_imp_data);
fseek($in->_imp_data, 0, SEEK_SET);
fseek($out->_imp_data, 0, SEEK_SET);
}
示例9: test_truncate_with_options_hash
function test_truncate_with_options_hash()
{
$this->assertEqual("This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", array("omission" => "[...]")));
$this->assertEqual("Hello W...", truncate("Hello World!", array("length" => 10)));
$this->assertEqual("Hello[...]", truncate("Hello World!", array("omission" => "[...]", "length" => 10)));
$this->assertEqual("Hello[...]", truncate("Hello Big World!", array("omission" => "[...]", "length" => 13, "separator" => ' ')));
$this->assertEqual("Hello Big[...]", truncate("Hello Big World!", array("omission" => "[...]", "length" => 14, "separator" => ' ')));
$this->assertEqual("Hello Big[...]", truncate("Hello Big World!", array("omission" => "[...]", "length" => 15, "separator" => ' ')));
}
示例10: pingback_ping
public function pingback_ping($args)
{
$config = Config::current();
$linked_from = str_replace('&', '&', $args[0]);
$linked_to = str_replace('&', '&', $args[1]);
$cleaned_url = str_replace(array("http://www.", "http://"), "", $config->url);
if ($linked_to == $linked_from) {
return new IXR_ERROR(0, __("The from and to URLs cannot be the same."));
}
if (!substr_count($linked_to, $cleaned_url)) {
return new IXR_Error(0, __("There doesn't seem to be a valid link in your request."));
}
if (preg_match("/url=([^&#]+)/", $linked_to, $url)) {
$post = new Post(array("url" => $url[1]));
} else {
$post = MainController::current()->post_from_url(null, str_replace(rtrim($config->url, "/"), "/", $linked_to), true);
}
if (!$post) {
return new IXR_Error(33, __("I can't find a post from that URL."));
}
# Wait for the "from" server to publish
sleep(1);
$from = parse_url($linked_from);
if (empty($from["host"])) {
return false;
}
if (empty($from["scheme"]) or $from["scheme"] != "http") {
$linked_from = "http://" . $linked_from;
}
# Grab the page that linked here.
$content = get_remote($linked_from);
# Get the title of the page.
preg_match("/<title>([^<]+)<\\/title>/i", $content, $title);
$title = $title[1];
if (empty($title)) {
return new IXR_Error(32, __("There isn't a title on that page."));
}
$content = strip_tags($content, "<a>");
$url = preg_quote($linked_to, "/");
if (!preg_match("/<a[^>]*{$url}[^>]*>([^>]*)<\\/a>/", $content, $context)) {
$url = str_replace("&", "&", preg_quote($linked_to, "/"));
if (!preg_match("/<a[^>]*{$url}[^>]*>([^>]*)<\\/a>/", $content, $context)) {
$url = str_replace("&", "&", preg_quote($linked_to, "/"));
if (!preg_match("/<a[^>]*{$url}[^>]*>([^>]*)<\\/a>/", $content, $context)) {
return false;
}
}
}
$context[1] = truncate($context[1], 100, "...", true);
$excerpt = strip_tags(str_replace($context[0], $context[1], $content));
$match = preg_quote($context[1], "/");
$excerpt = preg_replace("/.*?\\s(.{0,100}{$match}.{0,100})\\s.*/s", "\\1", $excerpt);
$excerpt = "[...] " . trim(normalize($excerpt)) . " [...]";
Trigger::current()->call("pingback", $post, $linked_to, $linked_from, $title, $excerpt);
return _f("Pingback from %s to %s registered!", array($linked_from, $linked_to));
}
示例11: __construct
public function __construct($data = NULL)
{
gateKeeper();
$logged_in_user = getLoggedInUser();
if (!$data) {
// Get the comment body
$comment_body = getInput("comment");
// Get container url
$container_guid = getInput("guid");
} else {
$comment_body = $data['comment_body'];
$container_guid = $data['container_guid'];
}
$container = getEntity($container_guid);
$container_owner_guid = $container->owner_guid;
if ($container_owner_guid) {
$container_owner = getEntity($container_owner_guid);
}
$url = $container->getURL();
if (!$url) {
$url = getSiteURL();
}
// Create the comment
CommentsPlugin::createComment($container_guid, $comment_body);
if ($container_owner_guid) {
if ($container_owner_guid != getLoggedInUserGuid()) {
$params = array("to" => array($container_owner->full_name, $container_owner->email), "from" => array(getSiteName(), getSiteEmail()), "subject" => "You have a new comment.", "body" => "You have a new comment. Click <a href='{$url}'>Here</a> to view it.", "html" => true);
switch ($logged_in_user->getSetting("notify_when_comment")) {
case "email":
sendEmail($params);
break;
case "none":
break;
case "site":
notifyUser("comment", $container_guid, getLoggedInUserGuid(), $container_owner_guid);
break;
case "both":
sendEmail($params);
notifyUser("comment", $container_guid, getLoggedInUserGuid(), $container_owner_guid);
break;
}
}
}
runHook("add:comment:after");
if (getLoggedInUserGuid() != $container_owner_guid && $container_owner_guid) {
new Activity(getLoggedInUserGuid(), "activity:comment", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $container_owner->getURL(), $container_owner->full_name, $container->getURL(), translate($container->type), truncate($comment_body)));
} elseif (!$container_owner_guid) {
new Activity(getLoggedInUserGuid(), "activity:comment:own", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $container->getURL(), $container->title, translate($container->type), truncate($comment_body)));
}
// Return to container page.
forward();
}
示例12: __construct
public function __construct()
{
gateKeeper();
$email_users = array();
$container_guid = getInput("container_guid");
$topic = getEntity($container_guid);
$category_guid = $topic->container_guid;
$category = getEntity($category_guid);
$description = getInput("comment");
$comment = new Forumcomment();
$comment->description = $description;
$comment->container_guid = $container_guid;
$comment->category_guid = $category_guid;
$comment->owner_guid = getLoggedInUserGuid();
$comment->save();
new SystemMessage("Your comment has been posted.");
new Activity(getLoggedInUserGuid(), "forum:comment:posted", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $topic->getURL(), $topic->title, truncate($comment->description)), $container_guid, $category->access_id);
$all_comments = getEntities(array("type" => "Forumcomment", "metadata_name" => "container_guid", "metadata_value" => $container_guid));
$notify_users = array($topic->owner_guid);
$container_owner_guid = $topic->owner_guid;
$container_owner = getEntity($container_owner_guid);
if ($container_owner->notify_when_forum_comment_topic_i_own == "email" || $container_owner->notify_when_forum_comment_topic_i_own == "both") {
$email_users[] = $container_guid;
}
foreach ($all_comments as $comment) {
$user_guid = $comment->owner_guid;
$user = getEntity($user_guid);
switch ($user->notify_when_forum_comment_topic_i_own) {
case "both":
$notify_users[] = $comment->owner_guid;
$email_users[] = $comment->owner_guid;
break;
case "email":
$email_users[] = $comment->owner_guid;
break;
case "site":
$notify_users[] = $comment->owner_guid;
break;
case "none":
break;
}
}
$notify_users = array_unique($notify_users);
foreach ($notify_users as $user_guid) {
notifyUser("forumcomment", $container_guid, getLoggedInUserGuid(), $user_guid);
}
foreach ($email_users as $user) {
$params = array("to" => array($user->full_name, $user->email), "from" => array(getSiteName(), getSiteEmail()), "subject" => "You have a new comment.", "body" => "You have a new comment. Click <a href='{$url}'>Here</a> to view it.", "html" => true);
sendEmail($params);
}
forward();
}
示例13: save_note
function save_note($id, $title, $body)
{
if ($body == "" && $title == "") {
$title = "Empty note";
}
if (($title == "" || $title == "Empty note") && $body != "") {
$title = truncate(strip_tags($body), 30);
}
$db = new db();
$result = $db->update("notes", array("title" => $title, "body" => $body), "id = :id", array(":id" => $id));
$result = array("id" => $id, "title" => $title, "body" => $body);
return $result;
}
示例14: formatTeaser
function formatTeaser($r)
{
$teaser = '';
if (array_key_exists('highlight', $r)) {
$teaser = trim(preg_replace('/\\s+/', ' ', preg_replace('/^\\*{2,}.*?\\n/', '', $r['highlight']['description'][0])));
} elseif (array_key_exists('description', $r['_source'])) {
$teaser = truncate(trim(preg_replace('/\\s+/', ' ', preg_replace('/^\\*{2,}.*/m', '', $r['_source']['description']))));
}
if ($teaser == '') {
$teaser = 'No data.';
}
return strip_tags($teaser);
}
示例15: smarty_function_ajax_input
function smarty_function_ajax_input($params, &$smarty)
{
$id = $params['id'];
$class = $params['class'];
$value = $params['value'];
$default = $params['default'];
$display = $params['display'];
$mode = $params['mode'];
$noclear = $params['noclear'];
$truncate = (int) $params['truncate'];
$permission = $params['permission'];
$callSave = isset($params['file']) ? "saveField(this, " . $params['file'] . ")" : "saveField(this)";
$trucated = truncate($value, $truncate);
if ($mode == 'edit') {
$edit = 1;
} elseif ($mode == 'show') {
$edit = 0;
} else {
$edit = $value ? 0 : 1;
}
if (!$display) {
$display = 'block';
}
if (!$permission) {
$output .= '<div id="show-' . $id . '" class="' . $class . '" style="display:' . $display . '">';
$output .= $trucated ? $trucated : $default;
$output .= "</div>";
return $output;
} else {
$class .= " editable";
}
$output = '';
$output .= '<div id="show-' . $id . '" class="' . $class . '" style="display:' . ($edit ? 'none' : $display) . '" onClick="editaCampo(' . "'" . $id . "'" . ');">';
$output .= $edit ? $default : $trucated;
$output .= "</div>";
// TODO: escape value
$output .= '<input class="' . $class . '" id="input-' . $id . '" value="' . ($value ? $value : $default) . '" ';
if (!$value && !$noclear) {
$output .= " onFocus=\"limpaCampo('{$id}');\"";
}
$output .= " onChange=\"mudado['{$id}']=1; editing['{$id}'] = false;\" onBlur=\"{$callSave}\" style=\"display:" . ($edit ? $display : 'none') . "\">";
$output .= "<img id=\"error-{$id}\" class=\"gUpErrorImg\" style=\"display: none\" src=\"styles/estudiolivre/errorImg.png\" onMouseover=\"tooltip(errorMsg_{$id});\" onMouseout=\"nd();\"> ";
$output .= '<script language="JavaScript">';
$output .= ' display["' . $id . '"] = "' . $display . '";errorMsg_' . $id . ' = "";';
if ($truncate) {
$output .= ' truncations["' . $id . '"] = "' . $truncate . '";';
}
$output .= '</script>';
return $output;
}