本文整理汇总了PHP中fprintf函数的典型用法代码示例。如果您正苦于以下问题:PHP fprintf函数的具体用法?PHP fprintf怎么用?PHP fprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: usage
function usage()
{
fprintf(STDERR, "Usage: php midigrep.php -f <midi_file> [-r] {-c <channels> | -C <channels>}\n");
fprintf(STDERR, "ex) php midigrep.php -f in.mid -c 1\n");
fprintf(STDERR, "ex) php midigrep.php -f in.mid -c 1,2\n");
fprintf(STDERR, "ex) php midigrep.php -f in.mid -C 15,16\n");
}
示例2: registerUser
function registerUser($userName, $userMail, $userPasswd, $salt)
{
$fileMail = fopen("database/email", "a+");
if ($fileMail) {
mkdir("database/users/{$userName}", 0755);
mkdir("database/users/{$userName}/tasks", 0755);
$fileName = fopen("database/users/{$userName}/{$userName}.usr", "a+");
if ($fileName) {
$filePasswd = fopen("database/passwd", "a+");
if ($filePasswd) {
/* creating user file in database */
/* registering e-mail adress in database */
fprintf($fileMail, "{$userMail}\n");
fprintf($fileName, "{$userName}:{$userMail}\n");
/* registering user's password in database */
$PasswdCrypt = sha1(sha1("{$userPasswd}") . $salt);
fprintf($filePasswd, "{$userName}:{$PasswdCrypt}\n");
fclose($fileName);
} else {
rmdir("database/users/{$userName}");
rmdir("database/users/{$userName}/tasks");
}
fclose($fileMail);
} else {
rmdir("database/users/{$userName}");
rmdir("database/users/{$userName}/tasks");
}
fclose($filePasswd);
}
}
示例3: exportCSV
/**
* @param mixed $data A Traversable of CModel or a CModel where data will be fetch from
* @param array $attributes Attribute names of CModel to be exported.
* @param bool $endApplication Application will be ended if true. false to keep going and export more data. Defautls to TRUE.
* @param integer $endLineCount Number of newlines to append below this data. Defaults to 0.
*/
public function exportCSV($data, $attributes = array(), $endApplication = true, $endLineCount = 0)
{
if ($this->isExportRequest()) {
$this->sendHeaders();
$fileHandle = fopen('php://output', 'w');
if ($data instanceof CActiveDataProvider) {
$this->csvRowHeaders($fileHandle, $attributes, $data->model);
$this->csvRowModels($fileHandle, new CDataProviderIterator($data, 150), $attributes);
} else {
if (is_array($data) && current($data) instanceof CModel) {
$this->csvRowHeaders($fileHandle, $attributes, current($data));
$this->csvRowModels($fileHandle, $data, $attributes);
} else {
if (is_array($data) && is_string(current($data))) {
fputcsv($fileHandle, $data, $this->csvDelimiter, $this->csvEnclosure);
} else {
if ($data instanceof CModel) {
$this->csvModel($fileHandle, $data, $attributes);
}
}
}
}
fprintf($fileHandle, str_repeat("\n", $endLineCount));
fclose($fileHandle);
if ($endApplication) {
Yii::app()->end(0, false);
exit(0);
}
}
}
示例4: do_app
function do_app($app)
{
// enumerate the host_app_versions for this app,
// joined to the host
$db = BoincDb::get();
$query = "select et_avg, host.on_frac, host.active_frac, host.gpu_active_frac, app_version.plan_class " . " from DBNAME.host_app_version, DBNAME.host, DBNAME.app_version " . " where host_app_version.app_version_id = app_version.id " . " and app_version.appid = {$app->id} " . " and et_n > 0 and et_avg > 0 " . " and host.id = host_app_version.host_id";
$result = $db->do_query($query);
$a = array();
while ($x = _mysql_fetch_object($result)) {
if (is_gpu($x->plan_class)) {
$av = $x->on_frac;
if ($x->gpu_active_frac) {
$av *= $x->gpu_active_frac;
} else {
$av *= $x->active_frac;
}
} else {
$av = $x->on_frac * $x->active_frac;
}
$a[] = 1 / $x->et_avg * $av;
}
_mysql_free_result($result);
sort($a);
$n = count($a);
$f = fopen("../../size_census_" . $app->name, "w");
for ($i = 1; $i < $app->n_size_classes; $i++) {
$k = (int) ($i * $n / $app->n_size_classes);
fprintf($f, "%e\n", $a[$k]);
}
fclose($f);
}
示例5: execute
/**
* Execute the command
*/
function execute()
{
$stderr = fopen('php://stdout', 'w');
$locales = AppLocale::getAllLocales();
$dbConn = DBConnection::getConn();
foreach ($locales as $locale => $localeName) {
fprintf($stderr, "Checking {$localeName}...\n");
$oldTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->oldTag);
$newTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->newTag);
if ($oldTemplatesText === false || $newTemplatesText === false) {
fprintf($stderr, "Skipping {$localeName}; could not fetch.\n");
continue;
}
$oldEmails = $this->parseEmails($oldTemplatesText);
$newEmails = $this->parseEmails($newTemplatesText);
foreach ($oldEmails['email_text'] as $oi => $junk) {
$key = $junk['attributes']['key'];
$ni = null;
foreach ($newEmails['email_text'] as $ni => $junk) {
if ($key == $junk['attributes']['key']) {
break;
}
}
if ($oldEmails['subject'][$oi]['value'] != $newEmails['subject'][$ni]['value']) {
echo "UPDATE email_templates_default_data SET subject='" . $dbConn->escape($newEmails['subject'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND subject='" . $dbConn->escape($oldEmails['subject'][$oi]['value']) . "';\n";
}
if ($oldEmails['body'][$oi]['value'] != $newEmails['body'][$ni]['value']) {
echo "UPDATE email_templates_default_data SET body='" . $dbConn->escape($newEmails['body'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND body='" . $dbConn->escape($oldEmails['body'][$oi]['value']) . "';\n";
}
}
}
fclose($stderr);
}
示例6: eputsf
function eputsf()
{
$args = func_get_args();
$fmt = array_shift($args);
fprintf(STDERR, $fmt, $args);
fprintf(STDERR, "%s", PHP_EOL);
}
示例7: ctx_log_msg
function ctx_log_msg($func, $text, $type)
{
global $_context_log;
if ($_context_log) {
fprintf($_context_log, "%f %s %d %d %s %s %s\n", microtime(true), php_uname('n'), posix_getpid(), posix_getpid(), $type, $func, $text);
}
}
示例8: usage
function usage()
{
global $argv;
fprintf(STDERR, "Usage: %s -u <URL> -n <requests> -c <concurrency> -e (use libevent)\n", $argv[0]);
fprintf(STDERR, "\nDefaults: -u http://localhost/ -n 1000 -c 10\n\n");
exit(-1);
}
示例9: main_loop
/**
* Simple tail program using the inotify extension
* Usage: ./tail.php file
*/
function main_loop($file, $file_fd)
{
$inotify = inotify_init();
if ($inotify === false) {
fprintf(STDERR, "Failed to obtain an inotify instance\n");
return 1;
}
$watch = inotify_add_watch($inotify, $file, IN_MODIFY);
if ($watch === false) {
fprintf(STDERR, "Failed to watch file '%s'", $file);
return 1;
}
while (($events = inotify_read($inotify)) !== false) {
echo "Event received !\n";
foreach ($events as $event) {
if (!($event['mask'] & IN_MODIFY)) {
continue;
}
echo stream_get_contents($file_fd);
break;
}
}
// May not happen
inotify_rm_watch($inotify, $watch);
fclose($inotify);
fclose($file_fd);
return 0;
}
示例10: processList
/**
* processList -
*/
function processList()
{
//$filename = 'titlelisting.txt';
$fp = fopen(self::RPT_FILENAME, 'w');
if ($fp) {
$this->fp = $fp;
}
//select nid, title from node order by title;
//$sql = 'SELECT nid, title FROM node ORDER BY title, nid LIMIT 50';
//$sql = "SELECT nid, title FROM node WHERE TYPE = 'biblio' ORDER BY title, nid LIMIT 500";
//SELECT n.nid, n.title FROM node AS n JOIN biblio AS b ON (b.nid = n.nid) WHERE b.biblio_label LIKE '%Pensoft%' AND n.type = 'biblio' ORDER BY n.title, n.nid LIMIT 10;
$sql = "SELECT nid, title FROM node WHERE TYPE = 'biblio' ORDER BY title, nid";
//$sql = "SELECT n.nid, n.title FROM node AS n JOIN biblio AS b ON (b.nid = n.nid) WHERE b.biblio_label LIKE '%Pensoft%' AND n.type = 'biblio' ORDER BY n.title, n.nid";
$titleList = $this->dbi->fetch($sql);
foreach ($titleList as $titleItem) {
//$msg = '' . $titleItem['nid'] . ' ' . (trim($titleItem['title']) ? $titleItem['title'] : 'NO TITLE') . ' ';
$msg = '' . $titleItem['nid'] . (strlen($titleItem['nid']) == 6 ? '' : ' ') . ' ' . (trim($titleItem['title']) ? $titleItem['title'] : 'NO TITLE') . ' ';
fprintf($this->fp, '%s', $msg);
fprintf($this->fp, '%s', PHP_EOL);
}
if ($this->fp) {
fclose($this->fp);
}
echo date('YmdHis');
}
示例11: export
function export($is_user, $dir)
{
$n = 0;
$filename = $is_user ? "{$dir}/user_work" : "{$dir}/team_work";
$f = fopen($filename, "w");
if (!$f) {
die("fopen");
}
$is_user ? fprintf($f, "<users>\n") : fprintf($f, "<teams>\n");
$maxid = $is_user ? BoincUser::max("id") : BoincTeam::max("id");
while ($n <= $maxid) {
$m = $n + 1000;
if ($is_user) {
$items = BoincUser::enum_fields("id", "id>={$n} and id<{$m} and total_credit>0");
} else {
$items = BoincTeam::enum_fields("id", "id>={$n} and id<{$m} and total_credit>0");
}
foreach ($items as $item) {
export_item($item, $is_user, $f);
}
$n = $m;
}
$is_user ? fprintf($f, "</users>\n") : fprintf($f, "</teams>\n");
fclose($f);
system("gzip -f {$filename}");
}
示例12: write_row
function write_row($handle, $row)
{
foreach ($row as $key => $value) {
$row[$key] = preg_replace("/\"/", "\"\"", $value);
}
fprintf($handle, "\"%s\"\n", implode("\",\"", $row));
}
示例13: write
public function write($message, $sev = 0)
{
$tag;
if ($sev < $this->debugLevel) {
return;
}
date_default_timezone_set("GMT");
switch ($sev) {
case 0:
$tag = "notice";
break;
case 1:
$tag = "warn";
break;
case 3:
$tag = "error";
break;
case 9:
$tag = "security";
break;
default:
$tag = "notice";
break;
}
$message = sprintf("[%s] [%s] [ppg] [session:%s] [prog:%s] : %s", date('D M d H:i:s Y'), $tag, $this->sessId, $this->caller, $message);
fprintf($this->errorHandle, "%s\n", $message);
}
示例14: prepare
/**
* @inheritdoc
*/
public function prepare()
{
if ($this->utf8Encoding) {
fprintf($this->getStream(), chr(0xef) . chr(0xbb) . chr(0xbf));
}
return $this;
}
示例15: createcfg
function createcfg($type = null)
{
$term = \Cherry\Cli\Console::getAdapter();
if (!$type) {
fprintf(STDERR, "No such config. Try " . Ansi::setUnderline() . "list-configs" . Ansi::clearUnderline() . "\n");
return 1;
}
$args = func_get_args();
$type = $args[0];
$opts = $this->parseOpts(array_slice($args, 1), array('verbose' => '+verbose', 'dest' => 'to:', 'force' => '+force'));
if ($type) {
$this->data = new TemplateStrings();
$this->data->htmlroot = exec('pwd');
$this->data->environment = 'prodution';
$tpl = (require CHERRY_LIB . '/share/configs/' . $type . '.php');
$meta = parse_ini_file(CHERRY_LIB . '/share/configs/' . $type . '.ini', true);
if (empty($opts['dest'])) {
$out = $meta['config']['dest'];
} else {
$out = $opts['dest'];
}
fprintf(STDOUT, "Writing %s...\n", $out);
if (file_exists($out)) {
if (empty($opts['force']) || $opts['force'] == 0) {
fprintf(STDERR, "Error: File already exists! To replace use +force\n");
return 1;
}
}
file_put_contents($out, trim($tpl) . "\n");
}
}