本文整理汇总了PHP中vfprintf函数的典型用法代码示例。如果您正苦于以下问题:PHP vfprintf函数的具体用法?PHP vfprintf怎么用?PHP vfprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vfprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
}
示例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);
}
示例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);
}
示例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===
示例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;
}
示例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===
示例7: printf
function printf($format, $args = array())
{
return vfprintf($this->stream, $format, $args);
}
示例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);
示例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);
}
示例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);
示例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===
示例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===
示例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);
示例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===
示例15: fpg_printf
function fpg_printf($format = "")
{
global $fpg_stream;
$args = func_get_args();
vfprintf($fpg_stream, $format . PHP_EOL, array_splice($args, 1));
}