本文整理汇总了PHP中array_trim函数的典型用法代码示例。如果您正苦于以下问题:PHP array_trim函数的具体用法?PHP array_trim怎么用?PHP array_trim使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_trim函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array_trim
/**
* 递归去除array中的空键
*/
function array_trim($array)
{
$array = (array) $array;
foreach ($array as $k => $v) {
if ($v == '' || $v == array()) {
unset($array[$k]);
} elseif (is_array($v)) {
$array[$k] = array_trim($v);
}
}
return $array;
}
示例2: array_trim
/**
* Trim all non-array values in an n-dimension array.
*/
function array_trim(&$arr)
{
if (!is_array($arr)) {
return false;
}
foreach ($arr as $key => $val) {
if (is_array($val)) {
array_trim($arr[$key]);
} else {
$arr[$key] = trim($arr[$key]);
}
}
}
示例3: storeSettingIpAddress
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function storeSettingIpAddress($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'ipaddress') {
$mysql_access_host_array = array_map('trim', explode(',', Settings::Get('system.mysql_access_host')));
$mysql_access_host_array[] = $newfieldvalue;
$mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
$mysql_access_host = implode(',', $mysql_access_host_array);
correctMysqlUsers($mysql_access_host_array);
Settings::Set('system.mysql_access_host', $mysql_access_host);
}
return $returnvalue;
}
示例4: parse
function parse($caching = true)
{
$feed = new SimplePie();
$feed->feed_url($this->uri);
$feed->cache_location(SIMPLEPIE_CACHE_DIR);
$feed->enable_caching($caching);
// parse
$parse_result = @$feed->init();
if ($parse_result === false) {
trigger_error("FeedParser::parse(): Failed to parse feed. uri: {$this->uri}", E_USER_NOTICE);
return false;
}
$feed->handle_content_type();
$link = $feed->get_feed_link();
$channel = array('title' => $feed->get_feed_title(), 'link' => $link, 'uri' => $this->uri, 'last_modified' => SimplePie_Sanitize::parse_date($feed->data['last-modified']), 'description' => $feed->get_feed_description());
// url
$url = new Net_URL($feed->get_feed_link());
$items = array();
$feed_items = @$feed->get_items();
if (is_array($feed_items)) {
foreach ($feed_items as $item) {
// category
$categories = $item->get_category();
if ($categories != '') {
$category = split(" ", $categories);
$category = array_trim($category);
} else {
$category = '';
}
// author
$author = '';
if (is_array($authors = $item->get_authors())) {
$men = array();
foreach ($item->get_authors() as $man) {
$men[] = $man->get_name();
}
$author = join(', ', $men);
}
// description
$description = $item->get_description();
if (empty($description)) {
$description = '';
}
$items[] = array('title' => $item->get_title(), 'uri' => $item->get_permalink(), 'description' => $description, 'date' => $item->get_date('U'), 'author' => $author, 'category' => $category);
}
}
$this->data = array('channel' => $channel, 'items' => $items);
$this->parser =& $feed;
unset($feed);
return true;
}
示例5: str_replace_array
/**
* Replaces Strings in an array, with the advantage that you
* can select which fields should be str_replace'd
*
* @param mixed String or array of strings to search for
* @param mixed String or array to replace with
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @return array The str_replace'd array
* @author Florian Lippert <flo@syscp.org>
*/
function str_replace_array($search, $replace, $subject, $fields = '')
{
if (is_array($subject)) {
$fields = array_trim(explode(' ', $fields));
foreach ($subject as $field => $value) {
if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
$subject[$field] = str_replace($search, $replace, $subject[$field]);
}
}
} else {
$subject = str_replace($search, $replace, $subject);
}
return $subject;
}
示例6: execute_document_ready
function execute_document_ready($l)
{
$document_ready_exposed = document_ready(true);
if ($document_ready_exposed != false) {
$document_ready_exposed = explode(' ', $document_ready_exposed);
$document_ready_exposed = array_unique($document_ready_exposed);
$document_ready_exposed = array_trim($document_ready_exposed);
foreach ($document_ready_exposed as $api_function) {
if (function_exists($api_function)) {
$l = $api_function($l);
}
}
}
return $l;
}
示例7: storeSettingMysqlAccessHost
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
*
* @version $Id$
*/
function storeSettingMysqlAccessHost($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'mysql_access_host') {
$mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
if (in_array('127.0.0.1', $mysql_access_host_array) && !in_array('localhost', $mysql_access_host_array)) {
$mysql_access_host_array[] = 'localhost';
}
if (!in_array('127.0.0.1', $mysql_access_host_array) && in_array('localhost', $mysql_access_host_array)) {
$mysql_access_host_array[] = '127.0.0.1';
}
$mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
$newfieldvalue = implode(',', $mysql_access_host_array);
correctMysqlUsers($mysql_access_host_array);
}
return $returnvalue;
}
示例8: htmlentities_array
/**
* Wrapper around htmlentities to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities
*
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @param int See php documentation about this
* @param string See php documentation about this
* @return array The array with htmlentitie'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function htmlentities_array($subject, $fields = '', $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
if (is_array($subject)) {
if (!is_array($fields)) {
$fields = array_trim(explode(' ', $fields));
}
foreach ($subject as $field => $value) {
if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = htmlentities_array($subject[$field], $fields, $quote_style, $charset);
}
}
} else {
$subject = htmlentities($subject, $quote_style, $charset);
}
return $subject;
}
示例9: array_clean
/** function array_clean [arrayClean]
* Strips out the unnecessary bits from an array
* so it can be input into a database, or to just
* generally clean an array of fluff
*
* @param array data array to be cleaned
* @param mixed csv or array of allowed keys
* @param mixed optional csv or array of required keys
* @return array
*/
function array_clean($array, $keys, $reqd = array())
{
if (!is_array($array)) {
return array();
}
array_trim($keys);
if (0 == count($keys)) {
throw new MyException(__FUNCTION__ . ': No keys given');
}
array_trim($reqd);
$return = array();
foreach ($keys as $key) {
if (in_array($key, $reqd) && empty($array[$key])) {
throw new MyException(__FUNCTION__ . ': Required element (' . $key . ') missing');
}
if (isset($array[$key])) {
$return[$key] = $array[$key];
}
}
return $return;
}
示例10: array_clean
/** function array_clean [arrayClean]
* Strips out the unnecessary bits from an array
* so it can be input into a database, or to just
* generally clean an array of fluff
*
* @param array $array data array to be cleaned
* @param mixed $keys csv or array of allowed keys
* @param mixed $required optional csv or array of required keys
*
* @return array
* @throws MyException
*/
function array_clean($array, $keys, $required = array())
{
if (!is_array($array)) {
return array();
}
array_trim($keys);
array_trim($required);
$keys = array_unique(array_merge($keys, $required));
if (empty($keys)) {
return array();
}
$return = array();
foreach ($keys as $key) {
if (in_array($key, $required) && empty($array[$key])) {
throw new MyException(__FUNCTION__ . ': Required element (' . $key . ') missing');
}
if (isset($array[$key])) {
$return[$key] = $array[$key];
}
}
return $return;
}
示例11: stripslashes_array
/**
* Wrapper around stripslashes to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities and with advantage,
* that you can eliminate all slashes by setting complete=true
*
* @param array The subject array
* @param int See php documentation about this
* @param string See php documentation about this
* @param string The fields which should be checked for, separated by spaces
* @param bool Select true to use stripslashes_complete instead of stripslashes
* @return array The array with stripslashe'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function stripslashes_array($subject, $fields = '', $complete = false)
{
if (is_array($subject)) {
if (!is_array($fields)) {
$fields = array_trim(explode(' ', $fields));
}
foreach ($subject as $field => $value) {
if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = stripslashes_array($subject[$field], $fields, $complete);
}
}
} else {
if ($complete == true) {
$subject = stripslashes_complete($subject);
} else {
$subject = stripslashes($subject);
}
}
return $subject;
}
示例12: update_password
public function update_password($data, $id)
{
if (array_valid($data) && is_valid_id($id)) {
// Ensure no bogus whitespace on any of the information
array_trim($data);
// Let's be sure the passwords match
$new_password = $data['magickey'];
$match_password = $data['matchkey'];
if ($new_password === $match_password) {
$update_data['magickey'] = sha1($new_password);
$this->db->where('id', $id);
$this->db->update('user', $update_data);
return TRUE;
} else {
$errors[] = 'The passwords for both fields did not match, please try again';
}
} else {
$errors[] = 'No user information was provided';
}
if (array_valid($errors)) {
return $errors;
}
}
示例13: html_entity_decode_array
/**
* Wrapper around html_entity_decode to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities and with advantage,
* that you can eliminate all html entities by setting complete=true
*
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @param bool Select true to use html_entity_decode_complete instead of html_entity_decode
* @param int See php documentation about this
* @param string See php documentation about this
* @return array The array with html_entity_decode'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function html_entity_decode_array($subject, $fields = '', $complete = false, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1')
{
if (is_array($subject)) {
if (!is_array($fields)) {
$fields = array_trim(explode(' ', $fields));
}
foreach ($subject as $field => $value) {
if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = html_entity_decode_array($subject[$field], $fields, $complete, $quote_style, $charset);
}
}
} else {
if ($complete == true) {
$subject = html_entity_decode_complete($subject, $quote_style, $charset);
} else {
$subject = html_entity_decode($subject, $quote_style, $charset);
}
}
return $subject;
}
示例14: array_trim
/**
* @example
* $value = [
* 'a' => [
* 'b' => [],
* ],
* 'c' => [
* 'd' => [
* 'e' => 1,
* ],
* ],
* ];
*
* // [
* // 'c' => [
* // 'd' => [
* // 'e' => 1,
* // ],
* // ],
* // ];
* $value = \Owl\array_trim($value);
*/
function array_trim(array $target)
{
$keys = array_keys($target);
$is_array = $keys === array_keys($keys);
$result = [];
foreach ($target as $key => $value) {
if (is_array($value) && $value) {
$value = array_trim($value);
}
if ($value === null || $value === '' || $value === []) {
continue;
}
$result[$key] = $value;
}
if ($is_array && $result) {
$result = array_values($result);
}
return $result;
}
示例15: array_trim
<td>
<input type='text' name='dfinal_dia' maxlength="2" size="2" /> /
<input type='text' name='dfinal_mes' maxlength="2" size="2" /> /
<input type='text' name='dfinal_ano' maxlength="4" size="4" />
</td>
</tr>
<tr>
<td colspan="2" class="bottom_row">
<input type='submit' value='Pesquisar' />
</td>
</tr>
</table>
</form>
<?php
} else {
$_POST = array_trim($_POST);
$data_inicial = implode('-', array($_POST['dinicial_ano'], $_POST['dinicial_mes'], $_POST['dinicial_dia']));
$data_final = implode('-', array($_POST['dfinal_ano'], $_POST['dfinal_mes'], $_POST['dfinal_dia']));
$c = new conexao();
$c->set_charset('utf8');
$q = "SELECT a.nome, b.* FROM usuarios AS a INNER JOIN logs AS b ON a.id = b.usuario_id WHERE horario BETWEEN '{$data_inicial}' AND '{$data_final}';";
$r = $c->query($q);
?>
<h2>Mostrando registros entre (<?php
echo $data_inicial;
?>
) e (<?php
echo $data_final;
?>
)</h2>
<table class="content_table">