本文整理汇总了PHP中trim函数的典型用法代码示例。如果您正苦于以下问题:PHP trim函数的具体用法?PHP trim怎么用?PHP trim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInput
protected function getInput()
{
if (!NNFrameworkFunctions::extensionInstalled('virtuemart')) {
return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('NN_FILES_NOT_FOUND', JText::_('NN_VIRTUEMART')) . '</fieldset>';
}
$this->params = $this->element->attributes();
$this->db = JFactory::getDBO();
$group = $this->get('group', 'categories');
$tables = $this->db->getTableList();
if (!in_array($this->db->getPrefix() . 'virtuemart_' . $group, $tables)) {
return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('NN_TABLE_NOT_FOUND', JText::_('NN_VIRTUEMART')) . '</fieldset>';
}
$parameters = NNParameters::getInstance();
$params = $parameters->getPluginParams('nnframework');
$this->max_list_count = $params->max_list_count;
if (!is_array($this->value)) {
$this->value = explode(',', $this->value);
}
$options = $this->{'get' . $group}();
$size = (int) $this->get('size');
$multiple = $this->get('multiple');
if ($group == 'categories') {
require_once JPATH_PLUGINS . '/system/nnframework/helpers/html.php';
return nnHtml::selectlist($options, $this->name, $this->value, $this->id, $size, $multiple);
}
$attr = '';
$attr .= ' size="' . (int) $size . '"';
$attr .= $multiple ? ' multiple="multiple"' : '';
return JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id);
}
示例2: _getSearchParam
/**
* Retrieve filter array
*
* @param Enterprise_Search_Model_Resource_Collection $collection
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
* @param string|array $value
* @return array
*/
protected function _getSearchParam($collection, $attribute, $value)
{
if (!is_string($value) && empty($value) || is_string($value) && strlen(trim($value)) == 0 || is_array($value) && isset($value['from']) && empty($value['from']) && isset($value['to']) && empty($value['to'])) {
return array();
}
if (!is_array($value)) {
$value = array($value);
}
$field = Mage::getResourceSingleton('enterprise_search/engine')->getSearchEngineFieldName($attribute, 'nav');
if ($attribute->getBackendType() == 'datetime') {
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
foreach ($value as &$val) {
if (!is_empty_date($val)) {
$date = new Zend_Date($val, $format);
$val = $date->toString(Zend_Date::ISO_8601) . 'Z';
}
}
unset($val);
}
if (empty($value)) {
return array();
} else {
return array($field => $value);
}
}
示例3: getSwarmUAIndex
/** @return object */
public static function getSwarmUAIndex()
{
// Lazy-init and cache
if (self::$swarmUaIndex === null) {
global $swarmInstallDir;
// Convert from array with string values
// to an object with boolean values
$swarmUaIndex = new stdClass();
$rawIndex = parse_ini_file("{$swarmInstallDir}/config/useragents.ini", true);
foreach ($rawIndex as $uaID => $uaItem) {
if (is_array($uaItem)) {
$uaItem2 = $uaItem;
foreach ($uaItem2 as $uaDataKey => $uaDataVal) {
if ($uaDataKey !== "displaytitle" && $uaDataKey !== "displayicon") {
$uaItem[$uaDataKey] = (bool) trim($uaDataVal);
} else {
$uaItem[$uaDataKey] = trim($uaDataVal);
}
}
if (!isset($uaItem["displaytitle"]) || !$uaItem["displaytitle"]) {
throw new SwarmException("User agent `{$uaID}` is missing a displaytitle property.");
}
if (!isset($uaItem["displayicon"]) || !$uaItem["displayicon"]) {
throw new SwarmException("User agent `{$uaID}` is missing a displayicon property.");
}
$swarmUaIndex->{$uaID} = (object) $uaItem;
}
}
self::$swarmUaIndex = $swarmUaIndex;
}
return self::$swarmUaIndex;
}
示例4: moduleValidateConfiguration
/**
* Performs payment module specific configuration validation
*
* @param string &$errorMessage - error message when return result is not true
*
* @return bool - true if configuration is valid, false otherwise
*
*
*/
function moduleValidateConfiguration(&$errorMessage)
{
global $providerConf;
$commomResult = commonValidateConfiguration($errorMessage);
if (!$commomResult) {
return false;
}
if (strlen(trim($providerConf['Param_sid'])) == 0) {
$errorMessage = '\'Account number\' field is empty';
return false;
}
if (!in_array($providerConf['Param_pay_method'], array('CC', 'CK'))) {
$errorMessage = '\'Pay method\' field has incorrect value';
return false;
}
if (strlen(trim($providerConf['Param_secret_word'])) == 0) {
$errorMessage = '\'Secret word\' field is empty';
return false;
}
if (strlen(trim($providerConf['Param_secret_word'])) > 16 || strpos($providerConf['Param_secret_word'], ' ') !== false) {
$errorMessage = '\'Secret word\' field has incorrect value';
return false;
}
return true;
}
示例5: apply
/**
* {@inheritdoc}
*/
public function apply(DataSourceInterface $dataSource, $name, $data, array $options)
{
$expressionBuilder = $dataSource->getExpressionBuilder();
if (is_array($data) && !isset($data['type'])) {
$data['type'] = isset($options['type']) ? $options['type'] : self::TYPE_CONTAINS;
}
if (!is_array($data)) {
$data = ['type' => self::TYPE_CONTAINS, 'value' => $data];
}
$fields = array_key_exists('fields', $options) ? $options['fields'] : [$name];
$type = $data['type'];
$value = array_key_exists('value', $data) ? $data['value'] : null;
if (!in_array($type, [self::TYPE_NOT_EMPTY, self::TYPE_EMPTY], true) && '' === trim($value)) {
return;
}
if (1 === count($fields)) {
$dataSource->restrict($this->getExpression($expressionBuilder, $type, current($fields), $value));
return;
}
$expressions = [];
foreach ($fields as $field) {
$expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value);
}
$dataSource->restrict($expressionBuilder->orX(...$expressions));
}
示例6: getstr
function getstr($string, $length, $in_slashes = 0, $out_slashes = 0, $bbcode = 0, $html = 0)
{
global $_G;
$string = trim($string);
$sppos = strpos($string, chr(0) . chr(0) . chr(0));
if ($sppos !== false) {
$string = substr($string, 0, $sppos);
}
if ($in_slashes) {
$string = dstripslashes($string);
}
$string = preg_replace("/\\[hide=?\\d*\\](.*?)\\[\\/hide\\]/is", '', $string);
if ($html < 0) {
$string = preg_replace("/(\\<[^\\<]*\\>|\r|\n|\\s|\\[.+?\\])/is", ' ', $string);
} elseif ($html == 0) {
$string = dhtmlspecialchars($string);
}
if ($length) {
$string = cutstr($string, $length);
}
if ($bbcode) {
require_once DISCUZ_ROOT . './source/class/class_bbcode.php';
$bb =& bbcode::instance();
$string = $bb->bbcode2html($string, $bbcode);
}
if ($out_slashes) {
$string = daddslashes($string);
}
return trim($string);
}
示例7: setUp
public function setUp(PDO $pdo, $sql)
{
$sql = explode(';', trim($sql));
foreach ($sql as $query) {
$pdo->exec(trim($query));
}
}
示例8: preUpload
/**
* @ORM\PreFlush()
*/
public function preUpload()
{
if ($this->file) {
if ($this->file instanceof FileUpload) {
$basename = $this->file->getSanitizedName();
$basename = $this->suggestName($this->getFilePath(), $basename);
$this->setName($basename);
} else {
$basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
$basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
$this->setName($basename);
}
if ($this->_oldPath && $this->_oldPath !== $this->path) {
@unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
}
if ($this->file instanceof FileUpload) {
$this->file->move($this->getFilePath());
} else {
copy($this->file->getPathname(), $this->getFilePath());
}
return $this->file = NULL;
}
if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
$oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
if (file_exists($oldFilePath)) {
rename($oldFilePath, $this->getFilePath());
}
}
}
示例9: pointorder_listOp
/**
* 积分兑换列表
*/
public function pointorder_listOp()
{
$model_pointorder = Model('pointorder');
//获取兑换订单状态
$pointorderstate_arr = $model_pointorder->getPointOrderStateBySign();
$where = array();
//兑换单号
$pordersn = trim($_GET['pordersn']);
if ($pordersn) {
$where['point_ordersn'] = array('like', "%{$pordersn}%");
}
//兑换会员名称
$pbuyname = trim($_GET['pbuyname']);
if (trim($_GET['pbuyname'])) {
$where['point_buyername'] = array('like', "%{$pbuyname}%");
}
//订单状态
if (trim($_GET['porderstate'])) {
$where['point_orderstate'] = $pointorderstate_arr[$_GET['porderstate']][0];
}
//查询兑换订单列表
$order_list = $model_pointorder->getPointOrderList($where, '*', 10, 0, 'point_orderid desc');
//信息输出
Tpl::output('pointorderstate_arr', $pointorderstate_arr);
Tpl::output('order_list', $order_list);
Tpl::output('show_page', $model_pointorder->showpage());
Tpl::showpage('pointorder.list');
}
示例10: PMA_getUploadStatus
/**
* Returns upload status.
*
* This is implementation for uploadprogress extension.
*/
function PMA_getUploadStatus($id)
{
global $SESSION_KEY;
global $ID_KEY;
if (trim($id) == "") {
return;
}
if (!array_key_exists($id, $_SESSION[$SESSION_KEY])) {
$_SESSION[$SESSION_KEY][$id] = array('id' => $id, 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0, 'plugin' => $ID_KEY);
}
$ret = $_SESSION[$SESSION_KEY][$id];
if (!PMA_import_uploadprogressCheck() || $ret['finished']) {
return $ret;
}
$status = uploadprogress_get_info($id);
if ($status) {
if ($status['bytes_uploaded'] == $status['bytes_total']) {
$ret['finished'] = true;
} else {
$ret['finished'] = false;
}
$ret['total'] = $status['bytes_total'];
$ret['complete'] = $status['bytes_uploaded'];
if ($ret['total'] > 0) {
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
}
} else {
$ret = array('id' => $id, 'finished' => true, 'percent' => 100, 'total' => $ret['total'], 'complete' => $ret['total'], 'plugin' => $ID_KEY);
}
$_SESSION[$SESSION_KEY][$id] = $ret;
return $ret;
}
示例11: __construct
public function __construct()
{
// if the route isn't specified, use the index controller
$this->route = isset($_GET['route']) ? htmlspecialchars($_GET['route']) : 'index';
$this->route = trim($this->route, '/');
// remove trailing slashes
}
示例12: updateNotice
public function updateNotice($data = array())
{
$update = array('TITLE' => trim($data['TITLE']), 'CONTENT' => json_encode($data['CONTENT']), 'START_DATE' => trim($data['START_DATE']), 'END_DATE' => trim($data['END_DATE']), 'IS_SHOW' => trim($data['IS_SHOW']), 'UPDATE_DATE' => date('Y-m-d H:i:s'));
$wheres = array('NOTICE_ID' => $data['NOTICE_ID']);
$this->db->where($wheres)->update('notices', $update);
return true;
}
示例13: ghost_command
public static function ghost_command($nick, $ircdata = array())
{
$unick = $ircdata[0];
$password = $ircdata[1];
// get the parameters.
if (trim($unick) == '' || trim($password) == '') {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_SYNTAX_RE, array('help' => 'GHOST'));
return false;
}
// invalid syntax
if (!isset(core::$nicks[$unick])) {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_NOT_IN_USE, array('nick' => $unick));
return false;
// nickname isn't in use
}
if ($user = services::user_exists($unick, false, array('display', 'pass', 'salt'))) {
if ($user->pass == sha1($password . $user->salt) || core::$nicks[$nick]['ircop'] && services::user_exists($nick, true, array('display', 'identified')) !== false) {
ircd::kill(core::$config->nickserv->nick, $unick, 'GHOST command used by ' . core::get_full_hostname($nick));
core::alog(core::$config->nickserv->nick . ': GHOST command used on ' . $unick . ' by ' . core::get_full_hostname($nick));
} else {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_PASSWORD);
// password isn't correct
}
} else {
services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_ISNT_REGISTERED, array('nick' => $unick));
return false;
// doesn't even exist..
}
}
示例14: process
function process($controller)
{
$this->_prepareFilter($controller);
$ret = array();
if (isset($controller->request->data)) {
//Loop for models
foreach ($controller->request->data as $key => $value) {
if (isset($controller->{$key})) {
$columns = $controller->{$key}->getColumnTypes();
foreach ($value as $k => $v) {
if ($v != '') {
//Trim the value
$v = trim($v);
//Check if there are some fieldFormatting set
if (isset($this->fieldFormatting[$columns[$k]])) {
$ret[sprintf($this->fieldFormatting[$columns[$k]][0], $key . '.' . $k, $v)] = sprintf($this->fieldFormatting[$columns[$k]][1], $key . '.' . $k, $v);
} else {
$ret[$key . '.' . $k] = $v;
}
}
}
//unsetting the empty forms
if (count($value) == 0) {
unset($controller->data[$key]);
}
}
}
}
return $ret;
}
示例15: validateString
/**
* validate a string
*
* @param mixed $str the value to evaluate as a string
*
* @throws \InvalidArgumentException if the submitted data can not be converted to string
*
* @return string
*/
protected function validateString($str)
{
if (is_object($str) && method_exists($str, '__toString') || is_string($str)) {
return trim($str);
}
throw new InvalidArgumentException('The data received is not OR can not be converted into a string');
}