Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

printf()

Send formatted text directly to output and return its byte count.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

printf(string $format, mixed ...$values): int

Send formatted text directly to output and return its byte count. Width and precision affect the output produced. A literal percent sign uses %%. To retain the formatted string rather than emitting it, use sprintf.

Signature

printf(string $format, mixed ...$values): int

Example output

0007:ok%
8

Examples

<?php
$written=printf("%04d:%s%%",7,"ok");
echo PHP_EOL,$written;

Result

0007:ok%
8

Sources