本文整理汇总了PHP中vsprintf函数的典型用法代码示例。如果您正苦于以下问题:PHP vsprintf函数的具体用法?PHP vsprintf怎么用?PHP vsprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vsprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _t
/**
* Translation helper
* It returns a translated string if it is found; Otherwise, the given string itself
*
* @param string $str The string being translated
* @param mixed $args The multiple arguments to be substituted in the string
*
* @return string The translated string
*/
function _t($str)
{
global $lc_lang;
global $lc_translation;
global $lc_translationEnabled;
$args = func_get_args();
$str = array_shift($args);
$str = trim($str);
if ($lc_translationEnabled == false) {
return count($args) ? vsprintf($str, $args) : $str;
}
$po = session_get('po');
if (!is_array($po)) {
$po = array();
}
$po[$str] = '';
if (isset($lc_translation[$lc_lang])) {
# check with lowercase
$lowerStr = strtolower($str);
if (isset($lc_translation[$lc_lang][$lowerStr]) && !empty($lc_translation[$lc_lang][$lowerStr])) {
$translated = $lc_translation[$lc_lang][$lowerStr];
$str = is_array($translated) ? $translated[0] : $translated;
}
}
if (isset($translated)) {
$po[$str] = $translated;
}
return count($args) ? vsprintf($str, $args) : $str;
}
示例2: process
public static function process($action = 'list', $id = null)
{
$errors = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $action == 'edit') {
// instancia
$data = array('id' => $_POST['id'], 'name' => $_POST['name'], 'amount' => $_POST['amount']);
if (WorthLib::save($data, $errors)) {
$action = 'list';
Message::Info(Text::_('Nivel de meritocracia modificado'));
// Evento Feed
$log = new Feed();
$log->populate(Text::_('Nivel de meritocracia modificado'), '/admin/worth', \vsprintf("El admin %s ha %s el nivel de meritocrácia %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Modificado'), Feed::item('project', $icon->name))));
$log->doAdmin('admin');
unset($log);
} else {
Message::Error(Text::_('No se ha guardado correctamente. ') . implode('<br />', $errors));
return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'edit', 'action' => 'edit', 'worth' => (object) $data));
}
}
switch ($action) {
case 'edit':
$worth = WorthLib::getAdmin($id);
return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'edit', 'action' => 'edit', 'worth' => $worth));
break;
}
$worthcracy = WorthLib::getAll();
return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'list', 'worthcracy' => $worthcracy));
}
示例3: query
/**
* Query database
*
* @param string $sql SQL Query
* @param array|string $replacement Replacement
* @return mixed
*/
public function query()
{
$args = func_get_args();
$sql = array_shift($args);
// Menerapkan $replacement ke pernyataan $sql
if (!empty($args)) {
$sql = vsprintf($sql, $args);
}
try {
// Return 'false' kalo belum ada koneksi
if (!$this->_db) {
$this->connect();
}
$this->_sql = $sql;
// Eksekusi SQL Query
if ($results = $this->_db->query($sql)) {
if (is_bool($results)) {
return $results;
}
$this->_results = $results;
$this->_num_rows = $this->_results->num_rows;
return $this;
} else {
App::error($this->_db->error . '<br>' . $this->_sql);
}
} catch (Exception $e) {
setAlert('error', $e->getMessage());
return false;
}
}
示例4: format
/**
* Creates an exception using a formatted message.
*
* @param string $format The message format.
* @param mixed $value,... A value.
*
* @return static The exception.
*/
public static function format($format, $value = null)
{
if (1 < func_num_args()) {
$format = vsprintf($format, array_slice(func_get_args(), 1));
}
return new static($format);
}
示例5: __construct
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
*
* @throws LackOfCoffeeException
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
if (!array_key_exists(static::class, static::$registered)) {
throw new LackOfCoffeeException(vsprintf('You forgot to call registerEvents() on %s.' . ' The method should be called on a Service Provider.' . ' See http://laravel.com/docs/5.1/eloquent#events' . ' for more details.', [static::class]));
}
}
示例6: get_link
/**
* Generate a URL to an endpoint
*
* Used to construct meta links in API responses
*
* @param mixed $args Optional arguments to be appended to URL
* @return string Endpoint URL
**/
function get_link()
{
$args = func_get_args();
$format = array_shift($args);
$base = WPCOM_JSON_API__BASE;
$path = array_pop($args);
if ($path) {
$path = '/' . ltrim($path, '/');
}
$args[] = $path;
// Escape any % in args before using sprintf
$escaped_args = array();
foreach ($args as $arg_key => $arg_value) {
$escaped_args[$arg_key] = str_replace('%', '%%', $arg_value);
}
$relative_path = vsprintf("{$format}%s", $escaped_args);
if (!wp_startswith($relative_path, '.')) {
// Generic version. Match the requested version as best we can
$api_version = $this->get_closest_version_of_endpoint($format, $relative_path);
$base = substr($base, 0, -1) . $api_version;
}
// escape any % in the relative path before running it through sprintf again
$relative_path = str_replace('%', '%%', $relative_path);
// http, WPCOM_JSON_API__BASE, ... , path
// %s , %s , $format, %s
return esc_url_raw(sprintf("https://%s{$relative_path}", $base));
}
示例7: init
public function init()
{
$description = $this->getTranslator()->translate('Conrols settings about access to the admin panel. <br>');
$settings = Engine_Api::_()->getApi('settings', 'core');
if ($settings->getSetting('user.support.links', 0) == 1) {
$moreinfo = $this->getTranslator()->translate('More Info: <a href="%1$s" target="_blank"> KB Article</a>');
} else {
$moreinfo = $this->getTranslator()->translate('');
}
$description = vsprintf($description . $moreinfo, array('http://support.socialengine.com/questions/170/Admin-Panel-Settings-Admin-Password'));
// Decorators
$this->loadDefaultDecorators();
$this->getDecorator('Description')->setOption('escape', false);
$this->setTitle('Admin Reauthentication')->setDescription($description);
// Mode
$this->addElement('Radio', 'mode', array('multiOptions' => array('none' => 'Do not require reauthentication.', 'user' => 'Require admins to re-enter their password when they try to access the admin panel.', 'global' => 'Require admins to enter a global password when they try to access the admin panel.')));
// Password
$this->addElement('Password', 'password', array('label' => 'Password', 'description' => 'The password for "Require admins to enter a global password when they try to access the admin panel." above (otherwise ignore).'));
// Password confirm
$this->addElement('Password', 'password_confirm', array('label' => 'Password Again', 'description' => 'Confirm password'));
// timeout
$this->addElement('Text', 'timeout', array('label' => 'Timeout', 'description' => 'How long (in seconds) before admins have to reauthenticate?', 'required' => true, 'allowEmpty' => false, 'validators' => array(array('NotEmpty', true), array('Int', true), array('Between', true, array(300, 86400)))));
// init submit
$this->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true));
}
示例8: setUp
public function setUp()
{
global $wpdb;
parent::setUp();
for ($i = 1; $i <= 13; $i++) {
$object = new \stdClass();
$object->ID = $i;
$this->results[] = $object;
}
$wpdb = m::mock('wpdb');
$wpdb->posts = 'wp_posts';
$wpdb->shouldReceive('prepare')->andReturnUsing(function () {
$args = func_get_args();
$query = array_shift($args);
// From WPDB::prepare method
$query = str_replace("'%s'", '%s', $query);
// in case someone mistakenly already singlequoted it
$query = str_replace('"%s"', '%s', $query);
// doublequote unquoting
$query = preg_replace('|(?<!%)%f|', '%F', $query);
// Force floats to be locale unaware
$query = preg_replace('|(?<!%)%s|', "'%s'", $query);
// quote the strings, avoiding escaped strings like %%s
return vsprintf($query, $args);
});
$wpdb->shouldReceive('_real_escape')->andReturnUsing(function ($arg) {
return $arg;
});
$wpdb->shouldReceive('get_var')->with("SELECT count(ID) FROM wp_posts WHERE post_type='post' AND post_status='publish'")->andReturn('13');
$wpdb->shouldReceive('get_results')->andReturn(array_slice($this->results, 0, 5), array_slice($this->results, 5, 5), array_slice($this->results, 10, 3));
}
示例9: getGUID
function getGUID()
{
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0xf | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
示例10: connect
/**
* Open a connection to the ActiveMQ queue.
*
* If there are queued subscriptions then these will be subscribed
* to once the connection is opened.
*
* @throws ConnectionErrorException
* @throws IncompatibleTopicException
*/
private function connect()
{
// Create DSN
$uri = vsprintf("%s://%s:%d", [self::SCHEME, self::HOST, self::PORT]);
// This will be populated with various exceptions that can happen when connecting.
$connectionError = false;
// Attempt to open a connection to Stomp server. Don't bail on exceptions.
try {
$this->stomp = new \Stomp($uri, $this->username, $this->password);
} catch (\Exception $e) {
$connectionError = $e->getMessage();
}
// If connection could not be opened, then bail with our ConnectionError exception.
// The passed argument is the message of the Stomp/PHP exception thrown earlier, if it exists.
if (!$this->stomp) {
throw new ConnectionErrorException($connectionError);
}
// If there are queued topics, then add them now that we have an open connection.
if (!empty($this->queuedTopics)) {
foreach ($this->queuedTopics as $topic) {
$this->addTopic($topic);
}
$this->queuedTopics = [];
}
}
示例11: transform
/**
* This method generates the checkstyle.xml report
*
* @param ProjectDescriptor $project Document containing the structure.
* @param Transformation $transformation Transformation to execute.
*
* @return void
*/
public function transform(ProjectDescriptor $project, Transformation $transformation)
{
$artifact = $this->getDestinationPath($transformation);
$this->checkForSpacesInPath($artifact);
$document = new \DOMDocument();
$document->formatOutput = true;
$report = $document->createElement('checkstyle');
$report->setAttribute('version', '1.3.0');
$document->appendChild($report);
/** @var FileDescriptor $fileDescriptor */
foreach ($project->getFiles()->getAll() as $fileDescriptor) {
$file = $document->createElement('file');
$file->setAttribute('name', $fileDescriptor->getPath());
$report->appendChild($file);
/** @var Error $error */
foreach ($fileDescriptor->getAllErrors()->getAll() as $error) {
$item = $document->createElement('error');
$item->setAttribute('line', $error->getLine());
$item->setAttribute('severity', $error->getSeverity());
$item->setAttribute('message', vsprintf($this->getTranslator()->translate($error->getCode()), $error->getContext()));
$item->setAttribute('source', 'phpDocumentor.file.' . $error->getCode());
$file->appendChild($item);
}
}
$this->saveCheckstyleReport($artifact, $document);
}
示例12: process
public static function process($action = 'list', $id = null, $filters = array())
{
$groups = Model\Icon::groups();
$errors = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// instancia
$icon = new Model\Icon(array('id' => $_POST['id'], 'name' => $_POST['name'], 'description' => $_POST['description'], 'order' => $_POST['order'], 'group' => empty($_POST['group']) ? null : $_POST['group']));
if ($icon->save($errors)) {
switch ($_POST['action']) {
case 'add':
Message::Info('Nuevo tipo añadido correctamente');
break;
case 'edit':
Message::Info('Tipo editado correctamente');
// Evento Feed
$log = new Feed();
$log->populate('modificacion de tipo de retorno/recompensa (admin)', '/admin/icons', \vsprintf("El admin %s ha %s el tipo de retorno/recompensa %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Modificado'), Feed::item('project', $icon->name))));
$log->doAdmin('admin');
unset($log);
break;
}
} else {
Message::Error(implode('<br />', $errors));
return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'edit', 'action' => $_POST['action'], 'icon' => $icon, 'groups' => $groups));
}
}
switch ($action) {
case 'edit':
$icon = Model\Icon::get($id);
return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'edit', 'action' => 'edit', 'icon' => $icon, 'groups' => $groups));
break;
}
$icons = Model\Icon::getAll($filters['group']);
return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'list', 'icons' => $icons, 'groups' => $groups, 'filters' => $filters));
}
示例13: postSendCode
public function postSendCode(Request $request)
{
//get data
extract($this->parseInput($request));
//validate
$verifyResult = SmsManager::validator(['mobile' => $mobile, 'seconds' => $seconds, 'uuid' => $uuid], $rule);
if (!$verifyResult['success']) {
return response()->json($verifyResult);
}
//send verify sms
$code = SmsManager::generateCode();
$minutes = SmsManager::getCodeValidTime();
$templates = SmsManager::getVerifySmsTemplates();
$template = SmsManager::getVerifySmsContent();
try {
$content = vsprintf($template, [$code, $minutes]);
} catch (\Exception $e) {
$content = $template;
}
$result = $this->phpSms->make($templates)->to($mobile)->data(['code' => $code, 'minutes' => $minutes])->content($content)->send();
if ($result['success']) {
$data = SmsManager::getSentInfo();
$data['sent'] = true;
$data['mobile'] = $mobile;
$data['code'] = $code;
$data['deadline_time'] = time() + $minutes * 60;
SmsManager::storeSentInfo($uuid, $data);
SmsManager::storeCanSendTime($uuid, $seconds);
$verifyResult = SmsManager::genResult(true, 'sms_send_success');
} else {
$verifyResult = SmsManager::genResult(false, 'sms_send_failure');
}
return response()->json($verifyResult);
}
示例14: writeLog
/**
* Write a message to Monolog.
*
* @param string $level
* @param string $message
* @param array $context
* @return void
*/
protected function writeLog($level, $message, $context)
{
$this->getFileInfo(self::TRACE_DEPTH);
$formatMessage = vsprintf(self::DEFAULT_LOG_FORMAT, array($this->getUrl(), $this->currentFile, $this->currentLine, $this->formatMessage($message)));
$this->fireLogEvent($level, $formatMessage, $context);
$this->monolog->{$level}($formatMessage, $context);
}
示例15: __construct
function __construct()
{
parent::__construct();
// Get CI instance to obtain DB settings
$ci =& get_instance();
$this->addConnection(array('driver' => 'mysql', 'host' => $ci->db->hostname, 'database' => $ci->db->database, 'username' => $ci->db->username, 'password' => $ci->db->password, 'charset' => $ci->db->char_set, 'collation' => $ci->db->dbcollat, 'prefix' => $ci->db->dbprefix));
// Listen to Model related events (saving, saved, updating, updated, creating, created etc).
$this->setEventDispatcher(new Dispatcher(new Container()));
// For CI Profiler (debugging utility)
$events = new Dispatcher();
$events->listen('illuminate.query', function ($query, $bindings, $time, $name) {
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {
if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} else {
if (is_string($binding)) {
$bindings[$i] = "'{$binding}'";
}
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
// Add it into CodeIgniter
$ci =& get_instance();
$ci->db->query_times[] = $time;
$ci->db->queries[] = $query;
});
$this->setEventDispatcher($events);
$this->setAsGlobal();
$this->bootEloquent();
}