本文整理汇总了PHP中str_ends_with函数的典型用法代码示例。如果您正苦于以下问题:PHP str_ends_with函数的具体用法?PHP str_ends_with怎么用?PHP str_ends_with使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_ends_with函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: env
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return value($default);
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'null':
case '(null)':
return null;
case 'empty':
case '(empty)':
return '';
}
if (str_starts_with($value, '"') && str_ends_with($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
示例2: ui
/**
* Loads the given jQuery UI components JS files.
*
* You can indicate the name of the JS files to include as follow:
*
* ```php
* $this->jQuery->ui('mouse', 'droppable', 'widget', ...);
* ```
*
* You can provide an array of options for HtmlHelper::script() as follow:
*
* ```php
* $this->jQuery->ui('mouse', 'droppable', ['block' => 'true'], 'widget', ...);
* ```
*
* If no component is given, all components (concatenated as a single JS file)
* will be loaded at once.
*
* @return mixed String of `<script />` tags or null if block is specified in
* options or if $once is true and the file has been included before
*/
public function ui()
{
$args = func_get_args();
$files = [];
$options = [];
$out = '';
foreach ($args as $file) {
if (is_array($file)) {
$options = $file;
continue;
}
$file = 'Jquery.ui/' . strtolower($file);
if (!str_ends_with($file, '.js')) {
$file .= '.js';
}
if ($file != 'Jquery.ui/core.js') {
$files[] = $file;
}
}
if (empty($files)) {
$files[] = Configure::read('debug') ? 'Jquery.jquery-ui.js' : 'Jquery.jquery-ui.min.js';
} else {
array_unshift($files, 'Jquery.ui/core.js');
}
foreach ($files as $file) {
$out .= (string) $this->_View->Html->script($file, $options);
}
if (empty($out)) {
return null;
}
return $out;
}
示例3: search
/**
* Execute search
*
* @param void
* @return null
*/
function search()
{
if (active_project() && !logged_user()->isProjectUser(active_project())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
// if
$pageType = array_var($_GET, 'page_type');
$search_for = array_var($_GET, 'search_for');
$objectManagers = array("ProjectWebpages", "ProjectMessages", "MailContents", "ProjectFiles", "ProjectMilestones", "ProjectTasks", "ProjectEvents");
$objectTypes = array(lang('webpages'), lang('messages'), lang('emails'), lang('files'), lang('milestones'), lang('tasks'), lang('events'));
$iconTypes = array('webpage', 'message', 'email', 'file', 'milestone', 'task', 'event');
if (user_config_option('show_file_revisions_search')) {
array_splice($objectManagers, 4, 0, 'ProjectFileRevisions');
array_splice($objectTypes, 4, 0, lang('file contents'));
array_splice($iconTypes, 4, 0, 'file');
}
$search_results = array();
$timeBegin = microtime(true);
if (trim($search_for) == '') {
$search_results = null;
$pagination = null;
} else {
$search_results = $this->searchWorkspaces($search_for, $search_results, 5);
$search_results = $this->searchUsers($search_for, $search_results, 5);
$search_results = $this->searchContacts($search_for, $search_results, 5);
if (array_var($_GET, 'search_all_projects') != "true" && active_project() instanceof Project) {
$projects = active_project()->getAllSubWorkspacesCSV(true);
} else {
$projects = null;
}
$c = 0;
foreach ($objectManagers as $om) {
$user_id = $om == "MailContents" ? logged_user()->getId() : 0;
$results = SearchableObjects::searchByType($search_for, $projects, $om, true, 5, 1, null, $user_id);
if (count($results[0]) > 0) {
$sr = array();
$sr['result'] = $results[0];
$sr['pagination'] = $results[1];
$sr['type'] = $objectTypes[$c];
$sr['icontype'] = $iconTypes[$c];
$sr['manager'] = $om;
$search_results[] = $sr;
}
$c++;
}
}
// if
$timeEnd = microtime(true);
if (str_starts_with($search_for, '"') && str_ends_with($search_for, '"')) {
$search_for = str_replace('"', '', $search_for);
}
tpl_assign('search_string', $search_for);
tpl_assign('search_results', $search_results);
tpl_assign('time', $timeEnd - $timeBegin);
ajx_set_no_toolbar(true);
ajx_replace(true);
}
示例4: testStrEndsWith
/**
* test str_ends_with
*/
public function testStrEndsWith()
{
$this->assertTrue(str_ends_with('foobar', 'bar'));
$this->assertTrue(str_ends_with('foobar', 'foobar'));
$this->assertFalse(str_ends_with('foobar', 'qux'));
$this->assertFalse(str_ends_with('foobar', 'foo'));
$this->assertFalse(str_ends_with('foobar', 'oba'));
$this->assertFalse(str_ends_with('foobar', 'quxfoobar'));
}
示例5: test_email
/**
* Test Mailer
*
* @param void
* @return null
*/
function test_email()
{
$email_data = $this->request->post('email');
if (!is_array($email_data)) {
$email_data = array('recipient' => $this->logged_user->getEmail(), 'subject' => lang('activeCollab - test email'), 'message' => lang("<p>Hi,</p>\n\n<p>Purpose of this message is to test whether activeCollab can send emails or not</p>"));
}
// if
$this->smarty->assign('email_data', $email_data);
if ($this->request->isSubmitted()) {
$errors = new ValidationErrors();
$subject = trim(array_var($email_data, 'subject'));
$message = trim(array_var($email_data, 'message'));
$recipient = trim(array_var($email_data, 'recipient'));
if ($subject == '') {
$errors->addError(lang('Message subject is required'), 'subject');
}
// if
if ($message == '') {
$errors->addError(lang('Message body is required'), 'message');
}
// if
if (is_valid_email($recipient)) {
$recipient_name = null;
$recipient_email = $recipient;
} else {
if (($pos = strpos($recipient, '<')) !== false && str_ends_with($recipient, '>')) {
$recipient_name = trim(substr($recipient, 0, $pos));
$recipient_email = trim(substr($recipient, $pos + 1, strlen($recipient) - $pos - 2));
if (!is_valid_email($recipient_email)) {
$errors->addError(lang('Invalid email address'), 'recipient');
}
// if
} else {
$errors->addError(lang('Invalid recipient'), 'recipient');
}
// if
}
// if
if ($errors->hasErrors()) {
$this->smarty->assign('errors', $errors);
$this->render();
}
// if
$mailer =& ApplicationMailer::mailer();
$email_message = new Swift_Message($subject, $message, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET);
if ($mailer->send($email_message, new Swift_Address($recipient_email, $recipient_name), $this->logged_user->getEmail())) {
flash_success('Test email has been sent, check your inbox');
} else {
flash_error('Failed to send out test email');
}
// if
$this->redirectTo('admin_tools_test_email');
}
// if
}
示例6: __construct
public function __construct()
{
parent::__construct();
$documentRoot = $this->getConfig("DocumentRootConnect");
if (str_ends_with($documentRoot, "/")) {
$documentRoot = substr($documentRoot, 0, -1);
}
$this->templatesDirectory = $_SERVER["DOCUMENT_ROOT"] . $documentRoot . DIRECTORY_SEPARATOR . $this->getConfig("TemplatesDirectory");
$this->cacheDirectory = $_SERVER["DOCUMENT_ROOT"] . $documentRoot . DIRECTORY_SEPARATOR . $this->getConfig("CacheDirectory");
$this->baseDirectory = $_SERVER["DOCUMENT_ROOT"] . $documentRoot;
}
示例7: url_trimAndClean
function url_trimAndClean($url)
{
$url = trim($url);
if (str_starts_with($url, '/')) {
$url = substr($url, 1);
}
if (str_ends_with($url, '/')) {
$url = substr($url, 0, strlen($url) - 1);
}
$url = strtolower($url);
return $url;
}
示例8: smarty_function_permission_name
/**
* Render verbose permission name
*
* @param array $params
* @param Smarty $smarty
* @return string
*/
function smarty_function_permission_name($params, &$smarty)
{
$name = array_var($params, 'name', 'unknown');
if (str_ends_with($name, '_add')) {
return lang('Add');
} elseif (str_ends_with($name, '_manage')) {
return lang('Edit and Delete');
} else {
return $name;
}
// if
}
示例9: _awaitingPlugins
/**
* Look for plugin/themes awaiting for installation and sets a flash message
* with instructions about how to proceed.
*
* @param string $type Possible values `plugin` (default) or `theme`, defaults
* to "plugin"
* @return void
*/
protected function _awaitingPlugins($type = 'plugin')
{
$type = !in_array($type, ['plugin', 'theme']) ? 'plugin' : $type;
$ignoreThemes = $type === 'plugin';
$plugins = Plugin::scan($ignoreThemes);
foreach ($plugins as $name => $path) {
if (Plugin::exists($name) || $type == 'theme' && !str_ends_with($name, 'Theme')) {
unset($plugins[$name]);
}
}
if (!empty($plugins)) {
$this->Flash->set(__d('system', '{0} are awaiting for installation', $type == 'plugin' ? __d('system', 'Some plugins') : __d('system', 'Some themes')), ['element' => 'System.stashed_plugins', 'params' => compact('plugins')]);
}
}
示例10: getSubscriberComments
static function getSubscriberComments($workspace = null, $tag = null, $orderBy = 'created_on', $orderDir = "DESC", $start = 0, $limit = 20)
{
$oc = new ObjectController();
$queries = $oc->getDashboardObjectQueries($workspace, $tag, false, false, $orderBy);
$query = '';
if (!is_array($queries)) {
return array();
}
foreach ($queries as $name => $q) {
if (str_ends_with($name, "Comments")) {
if ($query == '') {
$query = $q;
} else {
$query .= " \n UNION \n" . $q;
}
}
}
$query .= " ORDER BY `order_value` ";
if ($orderDir != "ASC" && $orderDir != "DESC") {
$orderDir = "DESC";
}
$query .= " " . $orderDir . " ";
$query .= " LIMIT " . $start . "," . $limit . " ";
$res = DB::execute($query);
$comments = array();
if (!$res) {
return $comments;
}
$rows = $res->fetchAll();
if (!is_array($rows)) {
return $comments;
}
foreach ($rows as $row) {
$manager = $row['object_manager_value'];
$id = $row['oid'];
if ($id && $manager) {
$comment = get_object_by_manager_and_id($id, $manager);
$object = $comment->getObject();
if ($object instanceof ProjectDataObject && $object->isSubscriber(logged_user())) {
$comments[] = $comment;
}
}
}
return $comments;
}
示例11: format_value_to_print_task
function format_value_to_print_task($value, $type, $textWrapper = '', $dateformat = 'Y-m-d')
{
switch ($type) {
case DATA_TYPE_STRING:
if (preg_match(EMAIL_FORMAT, strip_tags($value))) {
$formatted = $value;
} else {
$formatted = $textWrapper . clean($value) . $textWrapper;
}
break;
case DATA_TYPE_INTEGER:
$formatted = clean($value);
break;
case DATA_TYPE_BOOLEAN:
$formatted = $value == 1 ? lang('yes') : lang('no');
break;
case DATA_TYPE_DATE:
if ($value != 0) {
if (str_ends_with($value, "00:00:00")) {
$dateformat .= " H:i:s";
}
$dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value);
$formatted = format_date($dtVal, null, 0);
} else {
$formatted = '';
}
break;
case DATA_TYPE_DATETIME:
if ($value != 0) {
$dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value);
$formatted = format_date($dtVal, null, 0);
} else {
$formatted = '';
}
break;
default:
$formatted = $value;
}
if ($formatted == '') {
$formatted = '--';
}
return $formatted;
}
示例12: matches
private function matches($needle, $action)
{
if (array_key_exists($needle . '_' . $action, self::$cache['matches'])) {
return self::$cache['matches'][$needle . '_' . $action];
}
self::$cache['matches'][$needle . '_' . $action] = false;
$tneedle = strtoupper($needle);
$taction = strtoupper($action);
if (str_ends_with($tneedle, '.*') && str_starts_with($taction, substr($tneedle, 0, strlen($tneedle - 1)))) {
self::$cache['matches'][$needle . '_' . $action] = true;
} else {
if ($tneedle === $taction) {
self::$cache['matches'][$needle . '_' . $action] = true;
} else {
self::$cache['matches'][$needle . '_' . $action] = false;
}
}
return self::$cache['matches'][$needle . '_' . $action];
}
示例13: dirToArray
function dirToArray($dir, $fix = "", &$first = true)
{
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
dirToArray($dir . DIRECTORY_SEPARATOR . $file, $fix . $file . "/", $first);
} elseif (!str_ends_with($file, ".php") && !str_ends_with($file, ".md5") && !str_ends_with($file, ".dat") && !str_starts_with($file, "installer")) {
if ($first) {
$first = false;
} else {
print "\r\n";
}
print $fix . $file;
}
}
closedir($handle);
}
示例14: substr
function &loadTheme($name)
{
if (str_ends_with($this->themesDir, '/')) {
$this->themesDir = substr($this->themesDir, 0, strlen($this->themesDir) - 1);
}
$themeDir = $this->themesDir . '/' . $name . '/';
if (is_dir($themeDir)) {
$themeContext = file_exists($themeDir . '/theme-context.yml') ? $themeDir . '/theme-context.yml' : null;
if ($themeContext) {
AppContext::load($themeContext);
}
$bootstrap = file_exists($themeDir . '/bootstrap' . EXT) ? $themeDir . '/bootstrap' . EXT : null;
if ($bootstrap) {
include $bootstrap;
}
$theme =& new Theme($name, $themeDir);
return $theme;
}
show_error('ThemeManager', 'Specified theme doesn\'t exist: ' . $name);
}
示例15: upload
/**
* Uploads a ZIP package to the server.
*
* @return bool True on success
*/
public function upload()
{
if (!isset($this->_package['tmp_name']) || !is_readable($this->_package['tmp_name'])) {
$this->_error(__d('installer', 'Invalid package.'));
return false;
} elseif (!isset($this->_package['name']) || !str_ends_with(strtolower($this->_package['name']), '.zip')) {
$this->_error(__d('installer', 'Invalid package format, it is not a ZIP package.'));
return false;
} else {
$dst = normalizePath(TMP . $this->_package['name']);
if (is_readable($dst)) {
$file = new File($dst);
$file->delete();
}
if (move_uploaded_file($this->_package['tmp_name'], $dst)) {
$this->_dst = $dst;
return true;
}
}
$this->_error(__d('installer', 'Package could not be uploaded, please check write permissions on /tmp directory.'));
return false;
}