PHP equivalent of a Perl format function

Is there an equivalent to the Perl format function in PHP? I have a client who has a dotidata printer with a black collar, and I need a good way to format receipts and invoices with this secret beast.

I remember how easy it was to do this in perl with something like:

format BILLFORMAT = 
Name: @>>>>>>>>>>>>>>>>>>>>>>    Age: @###
      $name,                          $age
.
write;

Any ideas would be greatly appreciated by banging his head against the wall with this. Oo

UPDATE: I cannot install Perl in this environment, otherwise I would just use the Perl format function.

+3
source share
3 answers

You can use printf to do something like this.

http://www.php.net/manual/en/function.printf.php

printf("Name: %21s     Age: %3i\n",$name,$age);

If you want the name to be left justified, you would just add -

printf("Name: %-21s     Age: %3i\n",$name,$age);

.

+3

Perl , PHP Perl script.

PHP::Serialization Perl PHP. YAML JSON .

0

Sounds like the perfect situation to use heredoc .

-2
source

Source: https://habr.com/ru/post/1739890/


All Articles