本文整理汇总了PHP中array_pad函数的典型用法代码示例。如果您正苦于以下问题:PHP array_pad函数的具体用法?PHP array_pad怎么用?PHP array_pad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_pad函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Field
function Field()
{
$parts = explode("\n", chunk_split($this->value, 4, "\n"));
$parts = array_pad($parts, 4, "");
$field = "<span id=\"{$this->name}_Holder\" class=\"creditCardField\">" . "<input autocomplete=\"off\" name=\"{$this->name}[0]\" value=\"{$parts['0']}\" maxlength=\"4\"" . $this->getTabIndexHTML(0) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[1]\" value=\"{$parts['1']}\" maxlength=\"4\"" . $this->getTabIndexHTML(1) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[2]\" value=\"{$parts['2']}\" maxlength=\"4\"" . $this->getTabIndexHTML(2) . " /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"{$parts['3']}\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
return $field;
}
示例2: resize
public function resize($w, $h)
{
$this->width = $w;
$this->height = $h;
for ($i = 0; $i < count($this->data); $i++) {
$row =& $this->data[$i];
if ($row == null) {
$this->data[$i] = array();
$row =& $this->data[$i];
}
while (count($row) < $this->width) {
array_push($row, null);
}
unset($row);
}
if (count($this->data) < $this->height) {
$start = count($this->data);
for ($i = $start; $i < $this->height; $i++) {
$row = array();
$row = array_pad(array(), $this->width, null);
array_push($this->data, $row);
unset($row);
}
}
return true;
}
示例3: getRelativePath
public function getRelativePath($to)
{
// some compatibility fixes for Windows paths
$from = $this->from;
$from = is_dir($from) ? rtrim($from, '\\/') . '/' : $from;
$to = is_dir($to) ? rtrim($to, '\\/') . '/' : $to;
$from = str_replace('\\', '/', $from);
$to = str_replace('\\', '/', $to);
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach ($from as $depth => $dir) {
// find first non-matching dir
if ($dir === $to[$depth]) {
// ignore this directory
array_shift($relPath);
} else {
// get number of remaining dirs to $from
$remaining = count($from) - $depth;
if ($remaining > 1) {
// add traversals up to first matching dir
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './' . $relPath[0];
}
}
}
return implode('/', $relPath);
}
示例4: registerAuthorizer
/**
* Register the Authorization server with the IoC container.
*
* @param \Illuminate\Contracts\Container\Container $app
*
* @return void
*/
public function registerAuthorizer(Application $app)
{
$app->singleton('oauth2-server.authorizer', function ($app) {
$config = $app['config']->get('oauth2');
$issuer = $app->make(AuthorizationServer::class)->setClientStorage($app->make(ClientInterface::class))->setSessionStorage($app->make(SessionInterface::class))->setAuthCodeStorage($app->make(AuthCodeInterface::class))->setAccessTokenStorage($app->make(AccessTokenInterface::class))->setRefreshTokenStorage($app->make(RefreshTokenInterface::class))->setScopeStorage($app->make(ScopeInterface::class))->requireScopeParam($config['scope_param'])->setDefaultScope($config['default_scope'])->requireStateParam($config['state_param'])->setScopeDelimiter($config['scope_delimiter'])->setAccessTokenTTL($config['access_token_ttl']);
// add the supported grant types to the authorization server
foreach ($config['grant_types'] as $grantIdentifier => $grantParams) {
$grant = $app->make($grantParams['class']);
$grant->setAccessTokenTTL($grantParams['access_token_ttl']);
if (array_key_exists('callback', $grantParams)) {
list($className, $method) = array_pad(explode('@', $grantParams['callback']), 2, 'verify');
$verifier = $app->make($className);
$grant->setVerifyCredentialsCallback([$verifier, $method]);
}
if (array_key_exists('auth_token_ttl', $grantParams)) {
$grant->setAuthTokenTTL($grantParams['auth_token_ttl']);
}
if (array_key_exists('refresh_token_ttl', $grantParams)) {
$grant->setRefreshTokenTTL($grantParams['refresh_token_ttl']);
}
if (array_key_exists('rotate_refresh_tokens', $grantParams)) {
$grant->setRefreshTokenRotation($grantParams['rotate_refresh_tokens']);
}
$issuer->addGrantType($grant, $grantIdentifier);
}
$checker = $app->make(ResourceServer::class);
$authorizer = new Authorizer($issuer, $checker);
$authorizer->setRequest($app['request']);
$authorizer->setTokenType($app->make($config['token_type']));
$app->refresh('request', $authorizer, 'setRequest');
return $authorizer;
});
$app->alias('oauth2-server.authorizer', Authorizer::class);
}
示例5: emptyGuid
/**
* Returns a Guid object that has all its bits set to zero.
*
* @return Zend_Guid a nil Guid.
* @static
*/
public static function emptyGuid()
{
if (!isset($this->emptyGuid)) {
$this->emptyGuid = new Zend_Guid(array_pad(array(), 16, 0));
}
return $this->emptyGuid;
}
示例6: convert
function convert()
{
// arguments
if (func_num_args() === 0) {
return;
}
$args = func_get_args();
$body = array_pop($args);
$body = str_replace("\r", "\n", $body);
foreach ($args as $arg) {
list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
$this->options[$key] = $val;
}
$this->options['style'] = htmlspecialchars($this->options['style']);
$this->options['width'] = htmlspecialchars($this->options['width']);
// main
list($bodies, $splitargs) = $this->splitbody($body);
$splitoptions = array();
foreach ($splitargs as $i => $splitarg) {
$splitoptions[$i] = array();
foreach ($splitarg as $arg) {
list($key, $val) = array_pad(explode('=', $arg, 2), 2, true);
$splitoptions[$i][$key] = htmlspecialchars($val);
}
}
if ($this->options['tag'] == 'table') {
$output = $this->table($bodies, $splitoptions);
} else {
$output = $this->div($bodies, $splitoptions);
}
return $output;
}
示例7: verComp
function verComp($ver1, $ver2)
{
$v1 = explode(".", $ver1);
$v2 = explode(".", $ver2);
for ($i = 0; $i < count($v1); $i++) {
$v1[$i] = intval($v1[$i]);
}
for ($i = 0; $i < count($v2); $i++) {
$v2[$i] = intval($v2[$i]);
}
if (count($v1) < count($v2)) {
$v1 = array_pad($v1, count($v2));
}
if (count($v1) > count($v2)) {
$v2 = array_pad($v2, count($v1));
}
for ($i = 0; $i < count($v1); $i++) {
if ($v1[$i] > $v2[$i]) {
return 1;
}
if ($v1[$i] < $v2[$i]) {
return -1;
}
}
return 0;
}
示例8: __call
/**
* Magic call method
*
* @param string $method
* @param array $args
*/
public function __call($method, array $args = array())
{
if ($this->_logger) {
array_pad($args, 1);
$this->_logger->{$method}($args[0]);
}
}
示例9: balise_FORMULAIRE_INSCRIPTION_stat
/**
* Calculs de paramètres de contexte automatiques pour la balise FORMULAIRE_INSCRIPTION
*
* En absence de mode d'inscription transmis à la balise, celui-ci est
* calculé en fonction de la configuration :
*
* - '1comite' si les rédacteurs peuvent s'inscrire,
* - '6forum' sinon si les forums sur abonnements sont actifs,
* - rien sinon.
*
* @example
* ```
* #FORMULAIRE_INSCRIPTION
* [(#FORMULAIRE_INSCRIPTION{mode_inscription, #ID_RUBRIQUE})]
* ```
*
* @param array $args
* - args[0] un statut d'auteur (rédacteur par defaut)
* - args[1] indique la rubrique éventuelle de proposition
* @param array $context_compil
* Tableau d'informations sur la compilation
* @return array|string
* - Liste (statut, id) si un mode d'inscription est possible
* - chaîne vide sinon.
*/
function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil)
{
list($mode, $id) = array_pad($args, 2, null);
include_spip('action/inscrire_auteur');
$mode = tester_statut_inscription($mode, $id);
return $mode ? array($mode, $id) : '';
}
示例10: parse_url
/**
* @return array The return value should include 'errno' and 'data'
*/
function parse_url()
{
$request_uri = trim($_SERVER['REQUEST_URI']);
$request_uri = trim($request_uri, '/');
/* parse request uri start
* -----------------------------------
*/
$p = strpos($request_uri, '?');
$request_uri = $p !== false ? substr($request_uri, 0, $p) : $request_uri;
// security request uri filter
if (preg_match('/(\\.\\.|\\"|\'|<|>)/', $request_uri)) {
return array('errno' => self::ERRNO_FORBIDDEN, 'data' => "permission denied.");
}
// get display format
if (($p = strrpos($request_uri, '.')) !== false) {
$tail = substr($request_uri, $p + 1);
if (preg_match('/^[a-zA-Z0-9]+$/', $tail)) {
$display = $tail;
//'json'
$request_uri = substr($request_uri, 0, $p);
}
}
$url_piece = array_pad(explode('/', $request_uri, 5), 5, null);
return ['errno' => self::ERRNO_OK, 'data' => $url_piece];
}
示例11: IPv4To6
function IPv4To6($Ip, $expand = false)
{
static $Mask = '::ffff:';
// This tells IPv6 it has an IPv4 address
$IPv6 = strpos($Ip, ':') !== false;
$IPv4 = strpos($Ip, '.') !== false;
if (!$IPv4 && !$IPv6) {
return false;
}
if ($IPv6 && $IPv4) {
$Ip = substr($Ip, strrpos($Ip, ':') + 1);
} elseif (!$IPv4) {
return ExpandIPv6Notation($Ip);
}
// Seems to be IPv6 already?
$Ip = array_pad(explode('.', $Ip), 4, 0);
if (count($Ip) > 4) {
return false;
}
for ($i = 0; $i < 4; $i++) {
if ($Ip[$i] > 255) {
return false;
}
}
$Part7 = base_convert($Ip[0] * 256 + $Ip[1], 10, 16);
$Part8 = base_convert($Ip[2] * 256 + $Ip[3], 10, 16);
if ($expand) {
return ExpandIPv6Notation($Mask . $Part7 . ':' . $Part8);
} else {
return $Mask . $Part7 . ':' . $Part8;
}
}
示例12: pad
/**
* Pad to the specified size with a value.
*
* @param $size
* @param null $value
* @return $this
*/
public function pad($size, $value = null)
{
if ($this->isEmpty()) {
return $this;
}
return new static(array_pad($this->items, $size, $value));
}
示例13: run
public static function run($task, $args)
{
// Just call and run() or did they have a specific method in mind?
list($task, $method)=array_pad(explode(':', $task), 2, 'run');
$task = ucfirst(strtolower($task));
if ( ! $file = \Fuel::find_file('tasks', $task))
{
throw new \Exception('Well that didnt work...');
return;
}
require $file;
$task = '\\Fuel\\Tasks\\'.$task;
$new_task = new $task;
// The help option hs been called, so call help instead
if (\Cli::option('help') && is_callable(array($new_task, 'help')))
{
$method = 'help';
}
if ($return = call_user_func_array(array($new_task, $method), $args))
{
\Cli::write($return);
}
}
示例14: parse
protected static function parse($conf)
{
$routes = [];
$curpos = [];
foreach (explode("\n", $conf) as $line) {
if (($pos = strpos($line, '#')) !== false) {
$line = substr($line, 0, $pos);
}
if (!($line = rtrim($line))) {
continue;
}
$depth = strlen(preg_filter('/^(\\s+).*/', '$1', $line));
$data = preg_split('/\\s+/', ltrim($line));
$path = $data[0];
$node = $data[1] ?? null;
$curpos = array_slice($curpos, 0, $depth);
$curpos = array_pad($curpos, $depth, '');
$curpos[] = $path;
if (!$node) {
continue;
}
$line = preg_replace('/^\\s*.*?\\s+/', '', $line);
$path = preg_replace('/\\/+/', '/', '/' . join('/', $curpos));
$node = preg_replace('/\\s*/', '', $line);
$patt = str_replace('.', '\\.', $path);
$patt = preg_replace('/:\\w+/', '([^/]+)', $patt);
$patt = preg_replace('/@\\w+/', '(\\d+)', $patt);
$class = preg_replace('/\\//', '\\controller\\', dirname($node), 1);
$class = preg_replace('/\\//', '\\', $class);
$routes[] = ['path' => $path, 'controller' => dirname($node), 'action' => basename($node), 'pattern' => $patt, 'class' => $class];
}
return $routes;
}
示例15: save
public function save()
{
# Check we have the necessary data before proceeding.
foreach ($this->td->columns() as $col) {
# TODO: pk, not id
if ($col == "id") {
continue;
}
$coldata = $this->td->column($col);
if (!($coldata['is_nullable'] || !empty($this->data[$col]))) {
throw new Exception("{$col} must have value");
}
}
$query = "INSERT INTO `%s` (%s) VALUES (%s)";
$query_cols = array();
$query_vals = array();
foreach ($this->td->columns() as $col) {
# TODO: pk, not id
if ($col == "id") {
continue;
}
$coldata = $this->td->column($col);
#TODO: implement this.
# if ($coldata['is_ai']) continue;
$query_cols[] = "`{$col}`";
$query_vals[] = $this->data[$col];
}
# TODO: This will devolve into the query class eventually.
$query = sprintf($query, $this->td->table_name(), join(",", $query_cols), join(",", array_pad(array(), count($query_vals), "?")));
$this->schema->query($query, $query_vals);
}