Skip to content

Tag: printf

sprintf (PHP) return unwanted character (×) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed las…

PHP Printf As Float Precision

I am attempting to use PHP’s printf function to print out a user’s storage capacity. The full formula looks something like this: Given that $size == (10 * 1024 * 1024), this should print out 10.00 GB But it doesn’t. It prints 10.04 GB. Furthermore, results in 10.04 What?! In giving it an int…

Right justifying with printf

I’ve got a dictionary where both the keys and values are strings. I would like to print each key-value pair on its own line with the key left justified and the value right justified. Etc… What’s the best way to do this in PHP? Perhaps a clever way to do with printf? Answer Try this: The 40 t…

Why use sprintf function in PHP?

I am trying to learn more about the PHP function sprintf() but php.net did not help me much as I am still confused, why would you want to use it? Take a look at my example below. Why use this: When this does the same and is easier to write IMO: Am I missing something here? Answer sprintf has all