本文整理汇总了PHP中vfprintf函数的典型用法代码示例。如果您正苦于以下问题:PHP vfprintf函数的具体用法?PHP vfprintf怎么用?PHP vfprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vfprintf函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: print_line
function print_line($format, $args = array(), $where = STDOUT, $terminated_at_line = FALSE)
{
$args = is_null($args) ? array() : (is_array($args) ? $args : array($args));
vfprintf($where, $format . "\n", $args);
if ($terminated_at_line) {
die("\n\nExecution terminated at line #" . $terminated_at_line . "\n\n");
}
}
开发者ID:tahiryasin,项目名称:api-get-started,代码行数:8,代码来源:helpers.php
示例2: writeAndDump
function writeAndDump($fp, $format, $args)
{
ftruncate($fp, 0);
$length = vfprintf($fp, $format, $args);
rewind($fp);
$content = stream_get_contents($fp);
var_dump($content);
var_dump($length);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:vfprintf_variation1.php
示例3: write
/**
* Write some message to the stream,
* in a \c printf() fashion.
*
* \param string $format
* A format string to use to send the message.
*
* \note
* You may pass additional parameters to this
* method. They will serve as arguments for
* the format string.
*
* \note
* You don't need to add an end-of-line sequence
* to the format string, one will automatically
* be added for you by this method.
*/
public function write($format)
{
$args = func_get_args();
array_shift($args);
// Protection against format attacks.
if (!count($args)) {
$args[] = $format;
$format = "%s";
}
vfprintf($this->stream, $format . PHP_EOL, $args);
}
开发者ID:fpoirotte,项目名称:xrl,代码行数:28,代码来源:Output.php
示例4: vfprintf
*/
/*
* Test vfprintf() when different unsigned formats and unsigned values
* are passed to the '$format' and '$args' arguments of the function
*/
echo "*** Testing vfprintf() : unsigned formats and unsigned values ***\n";
// defining array of unsigned formats
$formats = array('%u %+u %-u', '%lu %Lu %4u %-4u', '%10.4u %-10.4u %.4u', '%\'#2u %\'2u %\'$2u %\'_2u', '%3$u %4$u %1$u %2$u');
// Arrays of unsigned values for the format defined in $format.
// Each sub array contains unsigned values which correspond to each format string in $format
$args_array = array(array(1234567, 01234567, 0), array(12345678900, 12345678900, 1234, 12345), array("1234000", 101234567000.0, 120.0), array(1, 0, 00, "10_"), array(3, 4, 1, 2));
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_variation15.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
// looping to test vfprintf() with different unsigned formats from the above $format array
// and with signed and other types of values from the above $args_array array
$counter = 1;
foreach ($formats as $format) {
fprintf($fp, "\n-- Iteration %d --\n", $counter);
vfprintf($fp, $format, $args_array[$counter - 1]);
$counter++;
}
fclose($fp);
print_r(file_get_contents($data_file));
echo "\n";
unlink($data_file);
?>
===DONE===
开发者ID:gleamingthecube,项目名称:php,代码行数:30,代码来源:ext_standard_tests_strings_vfprintf_variation15.php
示例5: printf
/**
* @param string[] $argv
* @param resource $stdin
* @param resource $stdout
* @param resource $stderr
* @return int UNIX status code
*/
function printf(array $argv, $stdin = STDIN, $stdout = STDOUT, $stderr = STDERR)
{
$format = array_shift($argv);
if ($format === null) {
fwrite($stderr, 'printf: not enough arguments' . PHP_EOL);
return 1;
}
$format = strtr($format, ['\\\\' => '\\', '\\a' => "\\a", '\\b' => "\\b", '\\c' => "\\c", '\\d' => "\\d", '\\e' => "", '\\f' => "\f", '\\g' => "\\g", '\\h' => "\\h", '\\i' => "\\i", '\\j' => "\\j", '\\k' => "\\k", '\\l' => "\\l", '\\m' => "\\m", '\\n' => "\n", '\\o' => "\\o", '\\p' => "\\p", '\\q' => "\\q", '\\r' => "\r", '\\s' => "\\s", '\\t' => "\t", '\\u' => "\\u", '\\v' => "\v", '\\w' => "\\w", '\\x' => "\\x", '\\y' => "\\y", '\\z' => "\\z"]);
\vfprintf($stdin, $format, $argv);
return 0;
}
开发者ID:BaguettePHP,项目名称:UnixCommand,代码行数:18,代码来源:functions.php
示例6: vfprintf
* are passed to the '$format' and '$args' arguments of the function
*/
echo "*** Testing vfprintf() : unsigned formats and signed & other types of values ***\n";
// defining array of unsigned formats
$formats = '%u %+u %-u
%lu %Lu %4u %-4u
%10.4u %-10.4u %.4u
%\'#2u %\'2u %\'$2u %\'_2u
%3$u %4$u %1$u %2$u';
// Arrays of signed and other type of values for the format defined in $format.
// Each sub array contains signed values which correspond to each format in $format
$args_array = array(array(+2.2, +0.2, +10.2, +123456.234, +123456.234, +1234.6789, +20000000000.0, +2000000000000.0, +22000000000000.0, +12345.78, +12.000000011111, -12.00000111111, -123456.234, +3.33, +4.44, +1.11, -2.22), array(" ", ' ', 'hello', '123hello', "123hello", '-123hello', '+123hello', "S45678hello", "-S45678hello", 'h123456ello', "1234hello", "helloworld", "NULL", "true", "3", "4", '1', '2'), array(array(0), array(1, 2), array(-1, -1), array("123"), array('123'), array('-123'), array("-123"), array(true), array(TRUE), array(FALSE), array("123hello"), array("1", "2"), array('123hello'), array(12 => "12twelve"), array("3"), array("4"), array("1"), array("2")), array(true, TRUE, false, TRUE, 0, FALSE, 1, true, TRUE, FALSE, 0, 1, 1, 0, 1, TRUE, 0, FALSE));
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_variation16.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
// looping to test vfprintf() with different unsigned formats from the above $format array
// and with signed and other types of values from the above $args_array array
$counter = 1;
foreach ($args_array as $args) {
fprintf($fp, "\n-- Iteration %d --\n", $counter);
vfprintf($fp, $formats, $args);
$counter++;
}
fclose($fp);
print_r(file_get_contents($data_file));
echo "\n";
unlink($data_file);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:vfprintf_variation16.php
示例7: printf
function printf($format, $args = array())
{
return vfprintf($this->stream, $format, $args);
}
开发者ID:chh,项目名称:ooio,代码行数:4,代码来源:Stream.php
示例8: fopen
<?php
/* Prototype : int vfprintf(resource stream, string format, array args)
* Description: Output a formatted string into a stream
* Source code: ext/standard/formatted_print.c
* Alias to functions:
*/
// Open handle
$file = 'vfprintf_error4.phpt.txt';
$fp = fopen($file, "a+");
echo "\n-- Testing vfprintf() function with other strangeties --\n";
var_dump(vfprintf('foo', 'bar', array('baz')));
var_dump(vfprintf($fp, 'Foo %$c-0202Sd', array(2)));
// Close handle
fclose($fp);
?>
===DONE===
<?php
error_reporting(0);
$file = 'vfprintf_error4.phpt.txt';
unlink($file);
开发者ID:badlamer,项目名称:hhvm,代码行数:21,代码来源:vfprintf_error4.php
示例9: error
/**
* @inheritdoc
* @see \pharext\Command::error()
*/
public function error($fmt)
{
if (!isset($fmt)) {
$fmt = "%s\n";
$arg = error_get_last()["message"];
} else {
$arg = array_slice(func_get_args(), 1);
}
vfprintf(STDERR, "ERROR: {$fmt}", $arg);
}
开发者ID:m6w6,项目名称:pharext,代码行数:14,代码来源:Command.php
示例10: fopen
<?php
/* Prototype : int vfprintf(resource stream, string format, array args)
* Description: Output a formatted string into a stream
* Source code: ext/standard/formatted_print.c
* Alias to functions:
*/
// Open handle
$file = 'vfprintf_error1.phpt.txt';
$fp = fopen($file, "a+");
echo "\n-- Testing vfprintf() function with more than expected no. of arguments --\n";
$format = 'string_val';
$args = array(1, 2);
$extra_arg = 10;
var_dump(vfprintf($fp, $format, $args, $extra_arg));
var_dump(vfprintf($fp, "Foo %d", array(6), "bar"));
// Close handle
fclose($fp);
?>
===DONE===
<?php
$file = 'vfprintf_error1.phpt.txt';
unlink($file);
开发者ID:alphaxxl,项目名称:hhvm,代码行数:23,代码来源:vfprintf_error1.php
示例11: __toString
// declaring a class
class sample
{
public function __toString()
{
return "object";
}
}
// Defining resource
$file_handle = fopen(__FILE__, 'r');
//array of values to iterate over
$values = array(0, 1, 12345, -2345, 10.5, -10.5, 101234567000.0, 1.07654321E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', "string", 'string', new sample(), @$undefined_var, @$unset_var, $file_handle);
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_variation21.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
fprintf($fp, "\n*** Testing vprintf() with unexpected values for args argument ***\n");
$counter = 1;
foreach ($values as $value) {
fprintf($fp, "\n-- Iteration %d --\n", $counter);
vfprintf($fp, $format, $value);
$counter++;
}
fclose($fp);
print_r(file_get_contents($data_file));
echo "\n";
unlink($data_file);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:vfprintf_variation21.php
示例12: vfprintf
* Source code: ext/standard/formatted_print.c
*/
/*
* Testing vfprintf() : basic functionality - using integer format
*/
echo "*** Testing vfprintf() : basic functionality - using integer format ***\n";
// Initialise all required variables
$format = "format";
$format1 = "%d";
$format2 = "%d %d";
$format3 = "%d %d %d";
$arg1 = array(111);
$arg2 = array(111, 222);
$arg3 = array(111, 222, 333);
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_basic2.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
vfprintf($fp, $format1, $arg1);
fprintf($fp, "\n");
vfprintf($fp, $format2, $arg2);
fprintf($fp, "\n");
vfprintf($fp, $format3, $arg3);
fprintf($fp, "\n");
fclose($fp);
print_r(file_get_contents($data_file));
unlink($data_file);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:vfprintf_basic2.php
示例13: fopen
<?php
/* Prototype : int vfprintf(resource stream, string format, array args)
* Description: Output a formatted string into a stream
* Source code: ext/standard/formatted_print.c
* Alias to functions:
*/
// Open handle
$file = 'vfprintf_error3.phpt.txt';
$fp = fopen($file, "a+");
echo "\n-- Testing vfprintf() function with wrong variable types as argument --\n";
var_dump(vfprintf($fp, array('foo %d', 'bar %s'), 3.55552));
rewind($fp);
var_dump(stream_get_contents($fp));
ftruncate($fp, 0);
rewind($fp);
var_dump(vfprintf($fp, "Foo %y fake", "not available"));
rewind($fp);
var_dump(stream_get_contents($fp));
ftruncate($fp, 0);
rewind($fp);
// Close handle
fclose($fp);
?>
===DONE===
<?php
$file = 'vfprintf_error3.phpt.txt';
unlink($file);
开发者ID:alphaxxl,项目名称:hhvm,代码行数:28,代码来源:vfprintf_error3.php
示例14: __toString
// declaring a class
class sample
{
public function __toString()
{
return "object";
}
}
// Defining resource
$file_handle = fopen(__FILE__, 'r');
//array of values to iterate over
$values = array(0, 1, 12345, -2345, 10.5, -10.5, 101234567000.0, 1.07654321E-9, 0.5, array(), array(0), array(1), array(1, 2), array('color' => 'red', 'item' => 'pen'), NULL, null, true, false, TRUE, FALSE, "", '', new sample(), @$undefined_var, @$unset_var, $file_handle);
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_variation20.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
fprintf($fp, "\n*** Testing vprintf() with with unexpected values for format argument ***\n");
$counter = 1;
foreach ($values as $value) {
fprintf($fp, "\n-- Iteration %d --\n", $counter);
vfprintf($fp, $value, $args);
$counter++;
}
fclose($fp);
print_r(file_get_contents($data_file));
echo "\n";
unlink($data_file);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:vfprintf_variation20.php
示例15: fpg_printf
function fpg_printf($format = "")
{
global $fpg_stream;
$args = func_get_args();
vfprintf($fpg_stream, $format . PHP_EOL, array_splice($args, 1));
}
开发者ID:maranemil,项目名称:php-fann,代码行数:6,代码来源:parameters_generator.php
示例16: fopen
<?php
/* Prototype : int vfprintf(resource stream, string format, array args)
* Description: Output a formatted string into a stream
* Source code: ext/standard/formatted_print.c
* Alias to functions:
*/
// Open handle
$file = 'vfprintf_error2.phpt.txt';
$fp = fopen($file, "a+");
echo "\n-- Testing vfprintf() function with less than expected no. of arguments --\n";
$format = 'string_val';
var_dump(vfprintf($fp, $format));
var_dump(vfprintf($fp));
var_dump(vfprintf());
// Close handle
fclose($fp);
?>
===DONE===
<?php
error_reporting(0);
$file = 'vfprintf_error2.phpt.txt';
unlink($file);
开发者ID:badlamer,项目名称:hhvm,代码行数:23,代码来源:vfprintf_error2.php
示例17: tempnam
<?php
$tempfile = tempnam('/tmp', 'vmextfiletest');
$f = fopen($tempfile, 'w');
vfprintf($f, "%s %s", array("testing", "vfprintf"));
fclose($f);
$f = fopen($tempfile, "r");
fpassthru($f);
echo "\n";
unlink($tempfile);
开发者ID:badlamer,项目名称:hhvm,代码行数:10,代码来源:vfprintf.php
示例18: vfprintf
/* Prototype : int vfprintf ( resource $handle , string $format , array $args )
* Description: Write a formatted string to a stream
* Source code: ext/standard/formatted_print.c
*/
echo "*** Testing vfprintf() : basic functionality - using string format ***\n";
// Initialise all required variables
$format = "format";
$format1 = "%s\n";
$format2 = "%s %s\n";
$format3 = "%s %s %s\n";
$arg1 = array("one");
$arg2 = array("one", "two");
$arg3 = array("one", "two", "three");
/* creating dumping file */
$data_file = dirname(__FILE__) . '/vfprintf_basic1.txt';
if (!($fp = fopen($data_file, 'wt'))) {
return;
}
$result = vfprintf($fp, $format1, $arg1);
var_dump($result);
$result = vfprintf($fp, $format2, $arg2);
var_dump($result);
$result = vfprintf($fp, $format3, $arg3);
var_dump($result);
fclose($fp);
print_r(file_get_contents($data_file));
unlink($data_file);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:vfprintf_basic1.php
示例19: var_dump
<?php
// Various functions that accept resource arguments have different coerce modes
// False
var_dump('fclose', @fclose(false));
var_dump('pclose', @pclose(false));
var_dump('fseek', @fseek(false, 0));
var_dump('rewind', @rewind(false));
var_dump('ftell', @ftell(false));
var_dump('feof', @feof(false));
var_dump('fstat', @fstat(false));
var_dump('fread', @fread(false, 0));
var_dump('fgetc', @fgetc(false));
var_dump('fgets', @fgets(false));
var_dump('fgetss', @fgetss(false));
var_dump('fscanf', @fscanf(false));
var_dump('fpassthru', @fpassthru(false));
var_dump('fwrite', @fwrite(false, ''));
var_dump('fputs', @fputs(false, ''));
var_dump('fprintf', @fprintf(false, ''));
var_dump('vfprintf', @vfprintf(false, '', array()));
var_dump('fflush', @fflush(false));
var_dump('ftruncate', @ftruncate(false));
// NULL
var_dump('fputcsv', @fputcsv(false, array()));
var_dump('fgetcsv', @fgetcsv(false));
var_dump('flock', @flock(false, 0));
var_dump('readdir', @readdir(false));
var_dump('rewinddir', @rewinddir(false));
var_dump('closedir', @closedir(false));
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:param_coerce_mode.php
注:本文中的vfprintf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论