本文整理汇总了PHP中utf8_substr函数的典型用法代码示例。如果您正苦于以下问题:PHP utf8_substr函数的具体用法?PHP utf8_substr怎么用?PHP utf8_substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utf8_substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resize
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return HTTPS_CATALOG . 'image/' . $new_image;
} else {
return HTTP_CATALOG . 'image/' . $new_image;
}
}
示例2: _insertIntoIndex
/**
* @param XenForo_Search_Indexer $indexer
* @param array $data
* @param array $parentData
*/
protected function _insertIntoIndex(XenForo_Search_Indexer $indexer, array $data, array $parentData = null)
{
$metadata = array();
$metadata['album'] = $data['album_id'];
if (!empty($data['photo_exif']) && !is_array($data['photo_exif'])) {
$data['photo_exif'] = @unserialize($data['photo_exif']);
}
if (!empty($data['photo_exif'])) {
if (isset($data['photo_exif']['Make']) && isset($data['photo_exif']['Model'])) {
$metadata['camera'] = $data['photo_exif']['Model'];
}
if (isset($data['photo_exif']['ExposureTime'])) {
$metadata['exposure'] = str_replace('/', '_', $data['photo_exif']['ExposureTime']);
}
if (isset($data['photo_exif']['FNumber'])) {
$f = explode('/', $data['photo_exif']['FNumber']);
$metadata['aperture'] = str_replace('.', '_', $f[1]);
}
if (isset($data['photo_exif']['FocalLength'])) {
$metadata['focal'] = str_replace('.', '_', str_replace('mm', '', $data['photo_exif']['FocalLength']));
}
if (isset($data['photo_exif']['ISOSpeedRatings'])) {
$metadata['iso'] = intval($data['photo_exif']['ISOSpeedRatings']);
}
}
if (!empty($data['collection_id'])) {
$metadata['collection'] = $data['collection_id'];
}
if (utf8_strlen($data['title']) > 250) {
$data['title'] = utf8_substr($data['title'], 0, 249);
}
$indexer->insertIntoIndex('sonnb_xengallery_photo', $data['content_id'], $data['title'], $data['description'], $data['content_date'], $data['user_id'], 0, $metadata);
}
示例3: utf8_str_pad
/**
* Replacement for str_pad. $padStr may contain multi-byte characters.
*
* @author Oliver Saunders <oliver (a) osinternetservices.com>
* @param string $input
* @param int $length
* @param string $padStr
* @param int $type ( same constants as str_pad )
* @return string
* @see http://www.php.net/str_pad
* @see utf8_substr
* @package utf8
* @subpackage strings
*/
function utf8_str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT)
{
$inputLen = utf8_strlen($input);
if ($length <= $inputLen) {
return $input;
}
$padStrLen = utf8_strlen($padStr);
$padLen = $length - $inputLen;
if ($type == STR_PAD_RIGHT) {
$repeatTimes = ceil($padLen / $padStrLen);
return utf8_substr($input . str_repeat($padStr, $repeatTimes), 0, $length);
}
if ($type == STR_PAD_LEFT) {
$repeatTimes = ceil($padLen / $padStrLen);
return utf8_substr(str_repeat($padStr, $repeatTimes), 0, floor($padLen)) . $input;
}
if ($type == STR_PAD_BOTH) {
$padLen /= 2;
$padAmountLeft = floor($padLen);
$padAmountRight = ceil($padLen);
$repeatTimesLeft = ceil($padAmountLeft / $padStrLen);
$repeatTimesRight = ceil($padAmountRight / $padStrLen);
$paddingLeft = utf8_substr(str_repeat($padStr, $repeatTimesLeft), 0, $padAmountLeft);
$paddingRight = utf8_substr(str_repeat($padStr, $repeatTimesRight), 0, $padAmountLeft);
return $paddingLeft . $input . $paddingRight;
}
trigger_error('utf8_str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
示例4: resize
public function resize($filename, $width, $height)
{
if (!is_file(DIR_IMAGE . $filename)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
示例5: index
public function index($setting)
{
$this->load->language('module/featured');
$this->load->language('common/common');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_heading_desc'] = $this->language->get('text_heading_desc');
$data['text_see_all'] = $this->language->get('text_see_all');
$data['text_newsevent'] = $this->language->get('text_newsevent');
$data['see_all_url'] = $this->url->link('product/manufacturer');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['products'] = array();
if (!$setting['limit']) {
$setting['limit'] = 9;
}
$products = array_slice($setting['product'], 0, (int) $setting['limit']);
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
$data['products'][] = array('product_id' => $product_info['product_id'], 'thumb' => $image, 'name' => $product_info['name'], 'manufacturer' => $product_info['manufacturer'], 'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']));
}
}
if ($data['products']) {
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/featured.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/featured.tpl', $data);
} else {
return $this->load->view('default/template/module/featured.tpl', $data);
}
}
}
示例6: getCategories
protected function getCategories($parent_id, $current_path = '')
{
$categoryhome = array();
$category_id = array_shift($this->path);
$results = $this->model_catalog_category->getCategories($parent_id);
$i = 0;
foreach ($results as $result) {
if (!$current_path) {
$new_path = $result['category_id'];
} else {
$new_path = $current_path . '_' . $result['category_id'];
}
if ($this->category_id == $result['category_id']) {
$categoryhome[$i]['href'] = $this->url->link('product/category', 'path=' . $new_path);
} else {
$categoryhome[$i]['href'] = $this->url->link('product/category', 'path=' . $new_path);
}
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$categoryhome[$i]['thumb'] = $this->model_tool_image->resize($image, 120, 120);
$categoryhome[$i]['name'] = $result['name'];
$categoryhome[$i]['description'] = utf8_substr(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 0, 100) . '..';
$i++;
}
return $categoryhome;
}
示例7: resize
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
$config['image_library'] = 'gd2';
$config['source_image'] = DIR_IMAGE . $old_image;
$config['new_image'] = DIR_IMAGE . $new_image;
$config['maintain_ratio'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
}
return HTTP_IMAGE . $new_image;
}
示例8: resize
/**
*
* @param filename string
* @param width
* @param height
* @param type char [default, w, h]
* default = scale with white space,
* w = fill according to width,
* h = fill according to height
*
*/
public function resize($filename, $width, $height, $type = "")
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height, $type);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return (defined('HTTPS_STATIC_CDN') ? HTTPS_STATIC_CDN : $this->config->get('config_ssl')) . 'image/' . $new_image;
} else {
return (defined('HTTP_STATIC_CDN') ? HTTP_STATIC_CDN : $this->config->get('config_url')) . 'image/' . $new_image;
}
}
示例9: index
public function index($setting)
{
$this->load->language('module/featuredcategory');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_view'] = $this->language->get('text_view');
$this->load->model('catalog/product');
$this->load->model('catalog/category');
$this->load->model('tool/image');
$data['products'] = array();
$products = explode(',', $this->config->get('featuredcategory_product'));
if (!$setting['limit']) {
$setting['limit'] = 4;
}
$products = array_slice($setting['product'], 0, (int) $setting['limit']);
foreach ($products as $category_id) {
$product_info = $this->model_catalog_category->getCategory($category_id);
if ($product_info) {
if ($product_info['image']) {
$image = $this->model_tool_image->resize($product_info['image'], $setting['width'], $setting['height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
}
$data['products'][] = array('category_id' => $product_info['category_id'], 'thumb' => $image, 'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 30) . '..', 'name' => $product_info['name'], 'href' => $this->url->link('product/category', 'path=' . $product_info['category_id']));
}
}
if ($data['products']) {
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/featuredcategory.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/featuredcategory.tpl', $data);
} else {
return $this->load->view('default/template/module/featuredcategory.tpl', $data);
}
}
}
示例10: cart
public function cart()
{
$this->load->model('tool/image');
$this->data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('image_cart_width'), $this->config->get('image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['option_value'];
} else {
$filename = $this->encryption->decrypt($option['option_value']);
$value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
}
$option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']);
}
$this->data['products'][] = array('product_id' => $product['product_id'], 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $product['tax_percentage'], 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']));
}
// Gift Voucher
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$this->data['products'][] = array('key' => $key, 'name' => $voucher['description'], 'price' => $voucher['amount'], 'amount' => 1, 'total' => $voucher['amount']);
}
}
$this->template = 'cart.tpl';
$this->response->setOutput($this->render());
}
示例11: substr
/**
* Shorten a string to a given number of characters
*
* The function preserves words, so the result might be a bit shorter or
* longer than the number of characters given. It strips all tags.
*
* @param string $strString The string to shorten
* @param integer $intNumberOfChars The target number of characters
* @param string $strEllipsis An optional ellipsis to append to the shortened string
*
* @return string The shortened string
*/
public static function substr($strString, $intNumberOfChars, $strEllipsis = ' …')
{
$strString = preg_replace('/[\\t\\n\\r]+/', ' ', $strString);
$strString = strip_tags($strString);
if (utf8_strlen($strString) <= $intNumberOfChars) {
return $strString;
}
$intCharCount = 0;
$arrWords = array();
$arrChunks = preg_split('/\\s+/', $strString);
$blnAddEllipsis = false;
foreach ($arrChunks as $strChunk) {
$intCharCount += utf8_strlen(static::decodeEntities($strChunk));
if ($intCharCount++ <= $intNumberOfChars) {
$arrWords[] = $strChunk;
continue;
}
// If the first word is longer than $intNumberOfChars already, shorten it
// with utf8_substr() so the method does not return an empty string.
if (empty($arrWords)) {
$arrWords[] = utf8_substr($strChunk, 0, $intNumberOfChars);
}
if ($strEllipsis !== false) {
$blnAddEllipsis = true;
}
break;
}
// Backwards compatibility
if ($strEllipsis === true) {
$strEllipsis = ' …';
}
return implode(' ', $arrWords) . ($blnAddEllipsis ? $strEllipsis : '');
}
示例12: index
public function index($setting)
{
if (empty($setting)) {
return;
}
$this->load->model('bossblog/article');
$this->load->language('module/blogrecentpost');
$boss_blogrecentpost = $setting['blogrecentpost_module'];
$data['text_postby'] = $this->language->get('text_postby');
$data['heading_title'] = isset($boss_blogrecentpost['title'][$this->config->get('config_language_id')]) ? $boss_blogrecentpost['title'][$this->config->get('config_language_id')] : '';
if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/bossthemes/bossblog.css')) {
$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/bossthemes/bossblog.css');
} else {
$this->document->addStyle('catalog/view/theme/default/stylesheet/bossthemes/bossblog.css');
}
$data['articles'] = array();
$data_sort = array('sort' => 'ba.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => $boss_blogrecentpost['limit']);
$results = $this->model_bossblog_article->getArticles($data_sort);
foreach ($results as $result) {
$data['articles'][] = array('blog_article_id' => $result['blog_article_id'], 'name' => $result['name'], 'title' => utf8_substr(strip_tags(html_entity_decode($result['title'], ENT_QUOTES, 'UTF-8')), 0, 50) . '...', 'date_added' => $result['date_added'], 'author' => $result['author'], 'href' => $this->url->link('bossblog/article', 'blog_article_id=' . $result['blog_article_id']));
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/blogrecentpost.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/module/blogrecentpost.tpl', $data);
} else {
return $this->load->view('default/template/module/blogrecentpost.tpl', $data);
}
}
示例13: convert_authors
function convert_authors($mysql_db, $sqlite_db, $min)
{
$sqlite_db->query("begin transaction;");
$sqlite_db->query("DELETE FROM authors");
$sqltest = "\n\tSELECT libavtorname.aid, libavtorname.FirstName, libavtorname.LastName, libavtorname.MiddleName, COUNT(libavtor.bid) as Number\n\tFROM libavtors AS libavtorname INNER JOIN (\n\t SELECT DISTINCT libavtor.aid, libavtor.bid\n\t FROM libavtor INNER JOIN libbook ON libbook.bid=libavtor.bid AND libavtor.role = 'a'\n\t) AS libavtor ON libavtorname.aid=libavtor.aid \n WHERE libavtorname.aid>{$min}\n\tGROUP BY libavtorname.aid, libavtorname.FirstName, libavtorname.LastName, libavtorname.MiddleName\n ";
$char_list = 'А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ы Э Ю Я A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';
$query = $mysql_db->query($sqltest);
while ($row = $query->fetch_array()) {
$full_name = trim($row['LastName']) . " " . trim($row['FirstName']) . " " . trim($row['MiddleName']);
$full_name = str_replace(" ", " ", $full_name);
$search_name = strtolowerEx($full_name);
$letter = utf8_substr($full_name, 0, 1);
$letter = strtoupperEx($letter, 0, 1);
if (strpos($char_list, $letter) === false) {
$letter = "#";
}
echo "Auth: " . $row['aid'] . " - " . $letter . " - " . $full_name . " - " . $search_name . "\n";
$sql = "INSERT INTO authors (id, number, letter, full_name, search_name, first_name, middle_name, last_name) VALUES(?,?,?,?,?,?,?,?)";
$insert = $sqlite_db->prepare($sql);
if ($insert === false) {
$err = $dbh->errorInfo();
die($err[2]);
}
$err = $insert->execute(array($row['aid'], $row['Number'], $letter, $full_name, $search_name, trim($row['FirstName']), trim($row['MiddleName']), trim($row['LastName'])));
if ($err === false) {
$err = $dbh->errorInfo();
die($err[2]);
}
$insert->closeCursor();
}
$sqlite_db->query("commit;");
}
示例14: showFirstLevel
public function showFirstLevel($message)
{
global $LANG, $CFG_GLPI;
$menu = $this->getMenu();
if ($message != '') {
echo "<div class='ui-loader ui-body-a ui-corner-all' id='messagebox' style='top: 75px;display:block'>";
echo "<h1>{$message}</h1>";
echo "</div>";
echo "<script>\n \$('#messagebox').delay(800).fadeOut(2000);\n </script>";
}
echo "<div data-role='content'>";
echo "<ul data-role='listview' data-inset='true' data-theme='c' data-dividertheme='a'>";
echo "<li data-role='list-divider'>" . $LANG['plugin_mobile']["title"] . "</li>";
$i = 1;
foreach ($menu as $part => $data) {
if (isset($data['content']) && count($data['content'])) {
echo "<li id='menu{$i}'>";
$link = $CFG_GLPI["root_doc"] . "/plugins/mobile/front/ss_menu.php?menu=" . $part;
if (Toolbox::strlen($data['title']) > 14) {
$data['title'] = utf8_substr($data['title'], 0, 14) . "...";
}
if (isset($data['icon'])) {
echo "<img src='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/pics/" . $data['icon'] . "' class='ui-li-icon round-icon' />";
}
echo "<a href=\"{$link}\" data-back='false'>" . $data['title'] . "</a>";
echo "</li>";
$i++;
}
}
echo "</ul>";
echo "</div>";
}
示例15: resize
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
try {
$image = new Image(DIR_IMAGE . $old_image);
} catch (Exception $exc) {
$this->log->write("The file {$old_image} has wrong format and can not be handled.");
$image = new Image(DIR_IMAGE . 'no_image.jpg');
}
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return HTTPS_IMAGE . $new_image;
} else {
return HTTP_IMAGE . $new_image;
}
}