本文整理汇总了PHP中String::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP String::truncate方法的具体用法?PHP String::truncate怎么用?PHP String::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatContent
/**
* Formats cell's content.
* @param mixed
* @param DibiRow|array
* @return string
*/
public function formatContent($value, $data = NULL)
{
$value = htmlSpecialChars($value);
if (is_array($this->replacement) && !empty($this->replacement)) {
if (in_array($value, array_keys($this->replacement))) {
$value = $this->replacement[$value];
}
}
foreach ($this->formatCallback as $callback) {
if (is_callable($callback)) {
$value = call_user_func($callback, $value, $data);
}
}
// translate & truncate
if ($value instanceof Html) {
$text = $this->dataGrid->translate($value->getText());
if ($this->maxLength != 0) {
$text = String::truncate($text, $this->maxLength);
}
$value->setText($text);
$value->title = $this->dataGrid->translate($value->title);
} else {
if ($this->maxLength != 0) {
$value = String::truncate($value, $this->maxLength);
}
}
return $value;
}
示例2: manageModule
/**
* Displays a table of the current modules content.
*
* Route: admin/multilanguage/modules/manage/:slug
*
* @param string $module The name of the module to get content for.
*/
public static function manageModule($module)
{
$output = array();
$content = Multilanguage::getModuleContent($module);
if ($content) {
foreach ($content as $type => $typeContent) {
$table = Html::table();
$header = $table->addHeader();
$header->addCol('Content');
if ($typeContent) {
foreach ($typeContent as $id => $data) {
$data = String::truncate($data, 200, '...');
$row = $table->addRow();
$row->addCol(Html::a()->get($data, 'admin/multilanguage/modules/manage/' . $module . '/' . $type . '/' . $id));
}
} else {
$table->addRow()->addCol('<em>No content.</em>');
}
$output[] = array('title' => ucfirst($type) . ' Content', 'content' => $table->render());
}
} else {
$output = array('title' => 'No Content', 'content' => '<p>This module has not specified any content to manage.</p>');
}
return $output;
}
示例3: for_display
public function for_display($table, $field_names, $objects)
{
foreach ($field_names as $field) {
$field_info[$field] = new Field_Information(array('name' => $field, 'table' => $table));
}
foreach ($objects as &$object) {
foreach ($field_info as $name => $info) {
if ($info->options !== NULL) {
$exploded_options = explode("\n", $info->options);
foreach ($exploded_options as $option) {
if (!empty($option)) {
$option_temp = explode(',', $option);
$options[$option_temp[0]] = $option_temp[1];
}
}
}
if ($info->type !== NULL) {
$field_type = $info->type;
$object->{$name} = $this->{$field_type}($object->{$name}, $options);
} else {
$object->{$name} = String::truncate(htmlspecialchars($object->{$name}), '400', '[...]');
}
}
}
return $objects;
}
示例4: excerpt
/**
* Returns a string of $length characters or less of the blog entry’s text
* that can be used as excerpt. HTML-Tags and UBB-Code is stripped
*
* @param $length
* @return string
*/
public function excerpt($length = 50)
{
if ($this->hasField('excerpt') && !$this->isEmpty('excerpt')) {
return $this->excerpt;
}
$firstWords = preg_replace('@\\[\\[([^\\]]+)\\]\\]@', '', $this->text);
$firstWords = String::truncate(strip_tags($firstWords), $length);
return $firstWords;
}
示例5: feed
/**
* Main RSS example.
*
* @return void
*/
public function feed()
{
if (empty($this->request->params['ext']) || $this->request->params['ext'] !== 'rss') {
throw new NotFoundException();
}
// This is only needed without the viewClassMap setting for RequestHandler
//$this->viewClass = 'Tools.Rss';
$this->News = ClassRegistry::init('Sandbox.NewsRecord');
$news = $this->News->feed();
$items = array();
foreach ($news as $key => $val) {
$content = nl2br(h($val['News']['content']));
$link = array('action' => 'feedview', $val['News']['id']);
$guidLink = array('action' => 'view', $val['News']['id']);
$items[] = array('title' => $val['News']['title'], 'link' => $link, 'guid' => array('url' => $guidLink, '@isPermaLink' => 'true'), 'description' => String::truncate($val['News']['content']), 'dc:creator' => $val['User']['username'], 'pubDate' => $val['News']['published'], 'content:encoded' => $content);
}
$atomLink = array('action' => 'feed', 'ext' => 'rss');
$channel = array('title' => __('News/Updates') . '', 'link' => '/', 'atom:link' => array('@href' => $atomLink), 'description' => __('Most recent news articles'), 'language' => 'en-en', 'image' => array('url' => '/img/statics/logo_rss.png', 'link' => '/'));
$data = array('document' => array(), 'channel' => $channel, 'items' => $items);
$this->set(array('channel' => $data, '_serialize' => 'channel'));
}
示例6: manageContent
/**
* Displays a form for creating a new translation of the current string. Also displays a table
* of current translations for the current string.
*
* Route: admin/multilanguage/strings/manage/:id
*
* @param int $id The id of the string to create translations for
*/
public static function manageContent($id)
{
if (!($string = Multilanguage::stringcontent()->find($id))) {
return ERROR_404;
}
if (isset($_POST['create_translation']) && Html::form()->validate()) {
$tmpId = Multilanguage::string()->insert(array('stringcontent_id' => $string->id, 'language_id' => $_POST['language_id'], 'content' => $_POST['content']));
if ($tmpId) {
Message::ok('Translation created successfully.');
unset($_POST['language_id']);
// Clear selected language
} else {
Message::error('Error creating translation, please try again.');
}
}
$langs = Multilanguage::language()->orderBy('name')->all();
$sortedLangs = array('' => 'Choose One');
foreach ($langs as $l) {
$sortedLangs[$l->id] = $l->name;
}
$form[] = array('fields' => array('language_id' => array('title' => 'Language', 'type' => 'select', 'options' => $sortedLangs, 'validate' => array('required')), 'content' => array('title' => 'Translated String', 'type' => strlen($string->content) > 25 ? 'textarea' : 'text', 'validate' => array('required'), 'default_value' => $string->content), 'create_translation' => array('type' => 'submit', 'value' => 'Create Translation')));
$table = Html::table();
$header = $table->addHeader();
$header->addCol('String');
$header->addCol('Language', array('colspan' => 2));
$translations = Multilanguage::string()->select('multilanguage_strings.*, multilanguage_languages.name AS language')->leftJoin('multilanguage_languages', 'multilanguage_languages.id', '=', 'multilanguage_strings.language_id')->where('multilanguage_strings.stringcontent_id', '=', $id)->orderBy('multilanguage_languages.name')->all();
if ($translations) {
foreach ($translations as $t) {
$row = $table->addRow();
$row->addCol(Html::a()->get(String::truncate($t->content, 100, '...'), 'admin/multilanguage/strings/edit/' . $id . '/' . $t->id));
$row->addCol($t->language);
$row->addCol(Html::a()->get('Delete', 'admin/multilanguage/strings/delete/' . $id . '/' . $t->id, array('onclick' => "return confirm('Delete this translation?')")), array('class' => 'right'));
}
} else {
$table->addRow()->addCol('<em>No translations.</em>', array('colspan' => 3));
}
return array(array('title' => 'Create String Translation', 'content' => Html::form()->build($form)), array('title' => 'Translations', 'content' => $table->render()));
}
示例7: preview
/**
* Display attachment preview for given $field
*
* @param string $field Attachment field name
* @param array $data Form data
* @param array $options
*
* @todo Use HtmlHelper compatible display tags for html outputs
*/
public function preview($field = null, $data = null, $options = array())
{
$this->setEntity($field);
$modelKey = $this->model();
$fieldKey = $this->field();
$options = am(array('label' => Inflector::humanize($fieldKey), 'size' => 'default', 'actionEdit' => false, 'actionDelete' => false), $options);
//TODO make actionUrl configurable
$actionUrl = am(array('plugin' => $this->request->params['plugin'], 'controller' => $this->request->params['controller'], 'action' => 'attachment'), $this->request->params['named'], $this->request->params['pass'], array('model' => $modelKey, 'field' => $fieldKey));
$attachments = $this->getAttachments($fieldKey, $data);
$label = $out = "";
if ($options['label']) {
$label = $this->Html->tag('label', $options['label']);
}
foreach ($attachments as $attachment) {
$_out = $_actions = "";
//thumb
$_out .= $this->Html->div('attachment-form-preview-thumb', $this->previewImage($attachment, array(), $options['size']));
//name
$_out .= $this->Html->div('attachment-form-preview-basename', $this->Html->link(String::truncate($attachment['basename'], 45), array(), array('title' => $attachment['basename'])));
//actionEdit
if ($options['actionEdit']) {
$editUrl = am($actionUrl, array('cmd' => 'edit'));
$_actions .= $this->Html->link(__('Edit'), $editUrl, array('class' => 'attachment-edit'));
}
//actionDelete
if ($options['actionDelete']) {
$deleteUrl = am($actionUrl, array('cmd' => 'delete'));
$_actions .= $this->Html->link(__('Delete'), $deleteUrl, array('class' => 'attachment-delete'), __("Do you really want to delete the attachment '%s'", $attachment['basename']));
}
$_out .= $this->Html->div('attachment-form-preview-actions', $_actions);
//wrap inner
$_out = $this->Html->div('attachment-form-preview', $_out);
//wrap outer
$out .= $this->Html->div('attachment-form-preview-wrap', $_out);
}
return $this->Html->div('attachment-form-container', $label . $out . '<div style="clear:both;"></div>');
}
示例8:
<div style="position: relative;" class="slideshow">
<a href="projects.php" title="View our Projects"><img src="images/banners/banner1.jpg" alt="" /></a>
<a href="projects.php" title="View our Projects"><img src="images/banners/banner2.jpg" alt="" /></a>
<a href="projects.php" title="View our Projects"><img src="images/banners/banner4.jpg" alt="" /></a>
</div>
</div>
<div class="sidebar">
<div class="overlap">
<div class="readmoreimg"><a href="about.php"><img src="images/readmore.png" alt="Read More..." title="Read More →" /></a></div>
<?php
echo String::truncate(BasicCms::block('about'), 500, '');
?>
<!--<div class="readmore"><a href="">Read More</a> →</div>-->
</div>
</div>
<div class="banners" style="border-right: 1px solid #b5b5b5;">
<a href="about.php"><img src="images/banners/aboutus.jpg" title="About Champion Builders, Inc." alt="" /></a>
<a href="services.php"><img src="images/banners/services.jpg" title="View our List of Services" alt="" /></a>
<a href="projects.php"><img src="images/banners/projects.jpg" title="View our Projects" alt="" /></a>
<a href="quote.php"><img src="images/banners/quote.jpg" title="Get a Quote" alt="" /></a>
<a href="kirby.php"><img src="images/banners/kirby.jpg" title="Kirby Building Systems Authorized Supplier" alt="" /></a>
<a href="employment.php"><img src="images/banners/employment.jpg" title="Want to work with Champion?" alt="" /></a>
示例9: foreach
<th>Date Submitted</th>
</tr>
<?php
foreach ($paginator->this_page() as $contact) {
?>
<tr>
<td><?php
echo $contact->name;
?>
</td>
<td><?php
echo $contact->email;
?>
</td>
<td><?php
echo String::truncate($contact->subject, 30);
?>
</td>
<td><?php
echo $contact->created_at;
?>
</td>
<td><a href="show.php?id=<?php
echo $contact->id;
?>
">Show</a></td>
</tr>
<?php
}
?>
</table>
示例10: __
<div id="header">
<span class="fl">
<?php
echo $HTML->link(Router::getRoute('root'), __('← zurück'), array('class' => 'button', 'title' => __('Den Admin verlassen und zur Website wechseln')));
?>
<?php
echo $HTML->link(Router::getRoute('admin'), Sanitizer::HTML(__('Administration :1', String::truncate(AppController::NAME, 40, '…'))));
?>
</span>
<span class="fr">
<?php
echo __('Eingeloggt als: :1 :2', $HTML->link($Me->adminDetailPageUri(), $Me->get('name')), $HTML->link(Router::getRoute('adminLogout'), __('logout'), array('class' => array('button', 'red'))));
?>
</span>
</div>
示例11: beforeRender
public function beforeRender()
{
// Site wide layout variables
$page_title_segments = $this->page_data['page_title'];
$this->page_data['page_id'] = $this->request->params['controller'] . '-' . md5($this->page_data['page_id']);
$this->page_data['page_title'] = implode(' – ', array_reverse($page_title_segments));
$this->page_data['page_image'] = Router::url($this->page_data['page_image'], true) . '?' . filemtime('.' . $this->page_data['page_image']);
$this->page_data['page_description'] = String::truncate(strip_tags($this->page_data['page_description']), 200, array('ellipsis' => '…'));
$this->page_data['page_url'] = Router::url(null, true);
// Facebook
$this->page_data['opengraph']['og:url'] = Router::url($this->here, true);
$this->page_data['opengraph']['og:title'] = $this->page_data['page_title'];
$this->page_data['opengraph']['og:description'] = $this->page_data['page_description'];
$this->page_data['opengraph']['og:image'] = Router::url('/img/share.jpg', true) . '?' . filemtime('./img/share.jpg');
$this->page_data['opengraph']['fb:app_id'] = Configure::read('Facebook.appId');
// Set body id
if ($this->name == 'CakeError') {
$this->page_data['body_id'] = 'error';
} else {
$this->page_data['body_id'] = strtolower("{$this->name}-{$this->action}");
}
if (isset($this->params['admin'])) {
$this->layout = 'admin';
// Role
$role = Configure::read('App.env') == 'development' ? 'superadmin' : $this->currentUser['Group']['name'];
$this->page_data['role'] = $role;
$this->page_data['admin_menu'] = $this->getAdminMenu($role);
} else {
}
$this->set($this->page_data);
return parent::beforeRender();
}
示例12: truncate
/**
* @see String::$truncate()
**/
function truncate($string, $limit, $pad = '...', $break = '.')
{
return String::truncate($string, $limit, $pad, $break);
}
示例13: testTruncate
/**
* truncate test.
* @return void
*/
public function testTruncate()
{
iconv_set_encoding('internal_encoding', 'UTF-8');
$s = "Řekněte, jak se (dnes) máte?";
// Řekněte, jak se (dnes) máte?
$this->assertEquals("…", String::truncate($s, -1), "length=-1");
$this->assertEquals("…", String::truncate($s, 0), "length=0");
$this->assertEquals("…", String::truncate($s, 1), "length=1");
$this->assertEquals("Ř…", String::truncate($s, 2), "length=2");
$this->assertEquals("Ře…", String::truncate($s, 3), "length=3");
$this->assertEquals("Řek…", String::truncate($s, 4), "length=4");
$this->assertEquals("Řekn…", String::truncate($s, 5), "length=5");
$this->assertEquals("Řekně…", String::truncate($s, 6), "length=6");
$this->assertEquals("Řeknět…", String::truncate($s, 7), "length=7");
$this->assertEquals("Řekněte…", String::truncate($s, 8), "length=8");
$this->assertEquals("Řekněte,…", String::truncate($s, 9), "length=9");
$this->assertEquals("Řekněte,…", String::truncate($s, 10), "length=10");
$this->assertEquals("Řekněte,…", String::truncate($s, 11), "length=11");
$this->assertEquals("Řekněte,…", String::truncate($s, 12), "length=12");
$this->assertEquals("Řekněte, jak…", String::truncate($s, 13), "length=13");
$this->assertEquals("Řekněte, jak…", String::truncate($s, 14), "length=14");
$this->assertEquals("Řekněte, jak…", String::truncate($s, 15), "length=15");
$this->assertEquals("Řekněte, jak se…", String::truncate($s, 16), "length=16");
$this->assertEquals("Řekněte, jak se …", String::truncate($s, 17), "length=17");
$this->assertEquals("Řekněte, jak se …", String::truncate($s, 18), "length=18");
$this->assertEquals("Řekněte, jak se …", String::truncate($s, 19), "length=19");
$this->assertEquals("Řekněte, jak se …", String::truncate($s, 20), "length=20");
$this->assertEquals("Řekněte, jak se …", String::truncate($s, 21), "length=21");
$this->assertEquals("Řekněte, jak se (dnes…", String::truncate($s, 22), "length=22");
$this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 23), "length=23");
$this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 24), "length=24");
$this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 25), "length=25");
$this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 26), "length=26");
$this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 27), "length=27");
$this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 28), "length=28");
$this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 29), "length=29");
$this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 30), "length=30");
$this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 31), "length=31");
$this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 32), "length=32");
}
示例14: formatFileName
/**
* Format the filename a specific way before uploading and attaching.
*
* @access public
* @param string $name - The current filename without extension
* @param string $field - The form field name
* @param array $file - The $_FILES data
* @return string
*/
function formatFileName($name, $field, $file)
{
$file = pathinfo($name);
$name = String::truncate($file['filename'], 20);
return Inflector::slug($name) . '_' . uniqid();
}
示例15: foreach
<?php
if (!empty($BlogPosts)) {
foreach ($BlogPosts as $entry) {
$text = $BlogPostFormater->format($entry->text);
if ($entry->isEmpty('headline')) {
$headline = String::truncate(strip_tags($text), 60, '…');
} else {
$headline = strip_tags($entry->get('headline'));
}
?>
<item>
<title><?php
echo strtr($headline, array('&' => '&'));
?>
</title>
<pubDate><?php
echo date('r', $entry->published);
?>
</pubDate>
<description><![CDATA[<?php
echo $text;
?>
]]></description>
<content:encoded><![CDATA[<?php
echo $text;
?>
<!-- p52h7fmk9e -->]]></content:encoded>
<guid isPermaLink="true"><?php
echo $entry->detailPageURL();
?>