本文整理汇总了PHP中String::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP String::substr方法的具体用法?PHP String::substr怎么用?PHP String::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterKeywords
/**
* Split a string into a clean array of keywords
* @param $text string
* @param $allowWildcards boolean
* @return array of keywords
*/
static function filterKeywords($text, $allowWildcards = false)
{
$minLength = Config::getVar('search', 'min_word_length');
$stopwords = self::_loadStopwords();
// Join multiple lines into a single string
if (is_array($text)) {
$text = join("\n", $text);
}
$cleanText = Core::cleanVar($text);
// Remove punctuation
$cleanText = String::regexp_replace('/[!"\\#\\$%\'\\(\\)\\.\\?@\\[\\]\\^`\\{\\}~]/', '', $cleanText);
$cleanText = String::regexp_replace('/[\\+,:;&\\/<=>\\|\\\\]/', ' ', $cleanText);
$cleanText = String::regexp_replace('/[\\*]/', $allowWildcards ? '%' : ' ', $cleanText);
$cleanText = String::strtolower($cleanText);
// Split into words
$words = String::regexp_split('/\\s+/', $cleanText);
// FIXME Do not perform further filtering for some fields, e.g., author names?
// Remove stopwords
$keywords = array();
foreach ($words as $k) {
if (!isset($stopwords[$k]) && String::strlen($k) >= $minLength && !is_numeric($k)) {
$keywords[] = String::substr($k, 0, SEARCH_KEYWORD_MAX_LENGTH);
}
}
return $keywords;
}
示例2: displayPaymentForm
function displayPaymentForm($queuedPaymentId, &$queuedPayment)
{
if (!$this->isConfigured()) {
return false;
}
$schedConf =& Request::getSchedConf();
$user =& Request::getUser();
$params = array('business' => $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'selleraccount'), 'item_name' => $queuedPayment->getDescription(), 'amount' => $queuedPayment->getAmount(), 'quantity' => 1, 'no_note' => 1, 'no_shipping' => 1, 'currency_code' => $queuedPayment->getCurrencyCode(), 'lc' => String::substr(Locale::getLocale(), 3), 'custom' => $queuedPaymentId, 'notify_url' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'ipn')), 'return' => $queuedPayment->getRequestUrl(), 'cancel_return' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'cancel')), 'first_name' => $user ? $user->getFirstName() : '', 'last_name' => $user ? $user->getLastname() : '', 'item_number' => 1, 'cmd' => '_xclick');
$templateMgr =& TemplateManager::getManager();
switch ($queuedPayment->getType()) {
case QUEUED_PAYMENT_TYPE_REGISTRATION:
// Provide registration-specific details to template.
$registrationDao =& DAORegistry::getDAO('RegistrationDAO');
$registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
$registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
$registration =& $registrationDao->getRegistration($queuedPayment->getAssocId());
if (!$registration || $registration->getUserId() != $queuedPayment->getUserId() || $registration->getSchedConfId() != $queuedPayment->getSchedConfId()) {
break;
}
$registrationOptionIterator =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
$registrationOptionCosts = $registrationTypeDao->getRegistrationOptionCosts($registration->getTypeId());
$registrationOptionIds = $registrationOptionDao->getRegistrationOptions($registration->getRegistrationId());
$templateMgr->assign('registration', $registration);
$templateMgr->assign('registrationType', $registrationTypeDao->getRegistrationType($registration->getTypeId()));
$templateMgr->assign('registrationOptions', $registrationOptionIterator->toArray());
$templateMgr->assign('registrationOptionCosts', $registrationOptionCosts);
$templateMgr->assign('registrationOptionIds', $registrationOptionIds);
}
$templateMgr->assign('params', $params);
$templateMgr->assign('paypalFormUrl', $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'paypalurl'));
$templateMgr->display($this->getTemplatePath() . 'paymentForm.tpl');
}
示例3: generateImage
function generateImage(&$captcha)
{
$width = $this->getWidth();
$height = $this->getHeight();
$length = String::strlen($captcha->getValue());
$value = $captcha->getValue();
$image = imagecreatetruecolor($width, $height);
$fg = imagecolorallocate($image, rand(128, 255), rand(128, 255), rand(128, 255));
$bg = imagecolorallocate($image, rand(0, 64), rand(0, 64), rand(0, 64));
imagefill($image, $width / 2, $height / 2, $bg);
$xStart = rand($width / 12, $width / 3);
$xEnd = rand($width * 2 / 3, $width * 11 / 12);
for ($i = 0; $i < $length; $i++) {
imagefttext($image, rand(20, 34), rand(-15, 15), $xStart + ($xEnd - $xStart) * $i / $length + rand(-5, 5), rand(40, 60), $fg, Config::getVar('captcha', 'font_location'), String::substr($value, $i, 1));
}
// Add some noise to the image.
for ($i = 0; $i < 20; $i++) {
$color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
for ($j = 0; $j < 20; $j++) {
imagesetpixel($image, rand(0, $this->getWidth()), rand(0, $this->getHeight()), $color);
}
}
header('Content-type: ' . $this->getMimeType());
imagepng($image);
imagedestroy($image);
}
示例4: generateFileName
/**
* Generate a filename for a library file.
* @param $type int LIBRARY_FILE_TYPE_...
* @param $originalFileName string
* @return string
*/
function generateFileName($type, $originalFileName)
{
$libraryFileDao =& DAORegistry::getDAO('LibraryFileDAO');
$suffix = $this->getFileSuffixFromType($type);
$ext = $this->getExtension($originalFileName);
$truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($suffix) - 1);
$baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
// Try a simple syntax first
$fileName = $baseName . '-' . $suffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
return $fileName;
}
for ($i = 1;; $i++) {
$fullSuffix = $suffix . '-' . $i;
//truncate more if necessary
$truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($fullSuffix) - 1);
// get the base name and append the suffix
$baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
//try the following
$fileName = $baseName . '-' . $fullSuffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
return $fileName;
}
}
}
示例5: initData
/**
* Initialize form data.
*/
function initData()
{
$PagSeguroPlugin =& $this->PagSeguroPlugin;
$user =& Request::getUser();
$userId = $user ? $user->getUserId() : null;
$queuedPayment =& $this->queuedPayment;
$this->_data = array('email_cobranca' => 'sbe@fgv.br', 'item_name' => $queuedPayment->getDescription(), 'a3' => $queuedPayment->getAmount($args), 'quantity' => 1, 'no_note' => 1, 'no_shipping' => 1, 'currency_code' => $queuedPayment->getCurrencyCode(), 'lc' => String::substr(Locale::getLocale(), 3), 'custom' => $this->key, 'notify_url' => Request::url(null, null, 'payment', 'ipn', array($queuedPayment->getQueuedPaymentId())), 'return' => Request::url(null, null, 'payment', 'return', array($queuedPayment->getQueuedPaymentId())), 'cancel_return' => Request::url(null, null, 'payment', 'cancel', array($queuedPayment->getQueuedPaymentId())), 'first_name' => $user ? $user->getFirstName() : '', 'last_name' => $user ? $user->getLastname() : '', 'city' => '', 'zip' => '', 'item_number' => 1);
}
示例6: filtreTitre
private function filtreTitre($ligneSummary)
{
$title = String::substr($ligneSummary, "- ", "\\");
$new = " " . substr($title, strrpos($title, "/") + 1);
$titreFinal = str_replace($title, $new, $ligneSummary);
$posFin = strpos($titreFinal, "\\");
$posFin = $posFin !== false ? $posFin : strlen($titreFinal);
$titreFinal = substr($titreFinal, 0, $posFin);
return $titreFinal;
}
示例7: getTemplateVarsFromRowColumn
/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $element mixed
* @param $columnId string
* @return array
*/
function getTemplateVarsFromRowColumn(&$row, $column)
{
$element =& $row->getData();
$columnId = $column->getId();
assert(is_a($element, 'DataObject') && !empty($columnId));
switch ($columnId) {
case 'titles':
$label = String::substr($element->getLocalizedQuestion(), 0, 20);
return array('label' => $label);
}
}
示例8: callback
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
*/
function callback($hookName, $args)
{
$request =& Registry::get('request');
$templateManager =& $args[0];
$allLocales = AppLocale::getAllLocales();
$localeList = array();
foreach ($allLocales as $key => $locale) {
$localeList[] = String::substr($key, 0, 2);
}
$templateManager->assign('additionalHeadData', $templateManager->get_template_vars('additionalHeadData') . $templateManager->fetch($this->getTemplatePath() . 'header.tpl'));
return false;
}
示例9: displayPaymentForm
function displayPaymentForm($queuedPaymentId, &$queuedPayment)
{
if (!$this->isConfigured()) {
return false;
}
$schedConf =& Request::getSchedConf();
$user =& Request::getUser();
$params = array('charset' => Config::getVar('i18n', 'client_charset'), 'business' => $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'selleraccount'), 'item_name' => $queuedPayment->getDescription(), 'amount' => $queuedPayment->getAmount(), 'quantity' => 1, 'no_note' => 1, 'no_shipping' => 1, 'currency_code' => $queuedPayment->getCurrencyCode(), 'lc' => String::substr(AppLocale::getLocale(), 3), 'custom' => $queuedPaymentId, 'notify_url' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'ipn')), 'return' => $queuedPayment->getRequestUrl(), 'cancel_return' => Request::url(null, null, 'payment', 'plugin', array($this->getName(), 'cancel')), 'first_name' => $user ? $user->getFirstName() : '', 'last_name' => $user ? $user->getLastname() : '', 'item_number' => 1, 'cmd' => '_xclick');
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign('params', $params);
$templateMgr->assign('paypalFormUrl', $this->getSetting($schedConf->getConferenceId(), $schedConf->getId(), 'paypalurl'));
$templateMgr->display($this->getTemplatePath() . 'paymentForm.tpl');
}
示例10: parseRecipe
/**
* Parse an item and return it as string
* @param object
* @param string
* @param integer
* @return string
*/
protected function parseRecipe($objRecipe, $strClass = '', $intCount = 0)
{
global $objPage;
$objTemplate = new \FrontendTemplate($this->item_template);
$objTemplate->setData($objRecipe->row());
$objTemplate->class = ($objRecipe->cssClass != '' ? ' ' . $objRecipe->cssClass : '') . $strClass;
// $objTemplate->distance = $this->getCurrentOpenStatus($objRecipe);
//Detail-Url
if ($this->jumpTo) {
$objDetailPage = \PageModel::findByPk($this->jumpTo);
$objTemplate->detailUrl = ampersand($this->generateFrontendUrl($objDetailPage->row(), '/' . $objRecipe->alias));
$objTemplate->teaser = \String::substr($objRecipe->preparation, 100);
}
return $objTemplate->parse();
}
示例11: callback
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
*/
function callback($hookName, $args)
{
$templateManager =& $args[0];
$request =& $this->getRequest();
$page = $request->getRequestedPage();
$op = $request->getRequestedOp();
$baseUrl = $templateManager->get_template_vars('baseUrl');
$additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
$allLocales = AppLocale::getAllLocales();
$localeList = array();
foreach ($allLocales as $key => $locale) {
$localeList[] = String::substr($key, 0, 2);
}
$tinymceScript = '
<script language="javascript" type="text/javascript" src="' . $baseUrl . '/' . TINYMCE_JS_PATH . '/tiny_mce_gzip.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE_GZ.init({
relative_urls : "false",
plugins : "paste,jbimages,fullscreen",
themes : "advanced",
languages : "' . join(',', $localeList) . '",
disk_cache : true
});
</script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
entity_encoding : "raw",
plugins : "paste,jbimages,fullscreen",
mode: "specific_textareas",
editor_selector: "richContent",
language : "' . String::substr(AppLocale::getLocale(), 0, 2) . '",
relative_urls : false,
forced_root_block : false,
apply_source_formatting : false,
theme : "advanced",
theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,bold,italic,underline,bullist,numlist,|,link,unlink,help,code,fullscreen,jbimages",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : ""
});
</script>';
$templateManager->assign('additionalHeadData', $additionalHeadData . "\n" . $tinymceScript);
return false;
}
示例12: getAllVarsFromURL
private function getAllVarsFromURL()
{
if (!empty($_GET['url'])) {
$vars = explode('/', $_GET['url']);
$args = array(0 => 'controller', 1 => 'action', 2 => 'id');
$i = 0;
foreach ($vars as $var) {
if (!empty($var)) {
if ($i < count($args) && !strpos($var, ':')) {
$this->vars[$args[$i]] = $var;
} else {
$key = String::strstr($var, ':', true);
$value = String::substr(String::strstr($var, ':'), 1);
if (!empty($key) && !empty($value)) {
$this->vars[$key] = $value;
}
}
++$i;
}
}
}
}
示例13: truncateFileName
/**
* Truncate a filename to fit in the specified length.
*/
function truncateFileName($fileName, $length = 127)
{
if (String::strlen($fileName) <= $length) {
return $fileName;
}
$ext = $this->getExtension($fileName);
$truncated = String::substr($fileName, 0, $length - 1 - String::strlen($ext)) . '.' . $ext;
return String::substr($truncated, 0, $length);
}
示例14: callback
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
*/
function callback($hookName, $args)
{
$templateManager =& $args[0];
$page = Request::getRequestedPage();
$op = Request::getRequestedOp();
$enableFields = $this->getEnableFields($templateManager, $page, $op);
if (!empty($enableFields)) {
$baseUrl = $templateManager->get_template_vars('baseUrl');
$additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
$enableFields = join(',', $enableFields);
$allLocales = Locale::getAllLocales();
$localeList = array();
foreach ($allLocales as $key => $locale) {
$localeList[] = String::substr($key, 0, 2);
}
$tinymceScript = '
<script language="javascript" type="text/javascript" src="' . $baseUrl . '/' . TINYMCE_JS_PATH . '/tiny_mce_gzip.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE_GZ.init({
relative_urls : "false",
plugins : "paste",
themes : "advanced",
languages : "' . join(',', $localeList) . '",
disk_cache : true
});
</script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
plugins : "paste",
mode : "exact",
language : "' . String::substr(Locale::getLocale(), 0, 2) . '",
elements : "' . $enableFields . '",
relative_urls : false,
forced_root_block : false,
apply_source_formatting : false,
theme : "advanced",
theme_advanced_buttons1 : "pasteword,bold,italic,underline,bullist,numlist,link,unlink,help,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : ""
});
</script>';
$templateManager->assign('additionalHeadData', $additionalHeadData . "\n" . $tinymceScript);
}
return false;
}
示例15: getAllArticles
public function getAllArticles()
{
$arrPids = array();
$arrAlias = array();
if (!$this->User->isAdmin) {
foreach ($this->User->pagemounts as $id) {
$arrPids[] = $id;
$arrPids = array_merge($arrPids, $this->Database->getChildRecords($id, 'tl_page'));
}
if (empty($arrPids)) {
return $arrAlias;
}
$objAlias = $this->Database->prepare("SELECT c.id, c.pid, c.type, (CASE c.type WHEN 'module' THEN m.name WHEN 'form' THEN f.title WHEN 'table' THEN c.summary ELSE c.headline END) AS headline, c.text, a.title FROM tl_content c LEFT JOIN tl_article a ON a.id=c.pid LEFT JOIN tl_module m ON m.id=c.module LEFT JOIN tl_form f on f.id=c.form WHERE a.pid IN(" . implode(',', array_map('intval', array_unique($arrPids))) . ") AND (c.ptable='tl_article' OR c.ptable='') AND c.id!=? ORDER BY a.title, c.sorting")->execute($this->Input->get('id'));
} else {
$objAlias = $this->Database->prepare("SELECT c.id, c.pid, c.type, (CASE c.type WHEN 'module' THEN m.name WHEN 'form' THEN f.title WHEN 'table' THEN c.summary ELSE c.headline END) AS headline, c.text, a.title FROM tl_content c LEFT JOIN tl_article a ON a.id=c.pid LEFT JOIN tl_module m ON m.id=c.module LEFT JOIN tl_form f on f.id=c.form WHERE (c.ptable='tl_article' OR c.ptable='') AND c.id!=? ORDER BY a.title, c.sorting")->execute($this->Input->get('id'));
}
while ($objAlias->next()) {
$arrHeadline = deserialize($objAlias->headline, true);
if (isset($arrHeadline['value'])) {
$headline = \String::substr($arrHeadline['value'], 32);
} else {
$headline = \String::substr(preg_replace('/[\\n\\r\\t]+/', ' ', $arrHeadline[0]), 32);
}
$text = \String::substr(strip_tags(preg_replace('/[\\n\\r\\t]+/', ' ', $objAlias->text)), 32);
$strText = $GLOBALS['TL_LANG']['CTE'][$objAlias->type][0] . ' (';
if ($headline != '') {
$strText .= $headline . ', ';
} elseif ($text != '') {
$strText .= $text . ', ';
}
$key = $objAlias->title . ' (ID ' . $objAlias->pid . ')';
$arrAlias[$key][$objAlias->id] = $strText . 'ID ' . $objAlias->id . ')';
}
return $arrAlias;
}