Jump to content

Is sprinf really needed?


Recommended Posts

I have looked through some files containing awful alot of sprinf everywhere and not just querys but eveylline of code they're echoing sprinf, like on money, name level displays ect..

So my question is, is it really needed? And if we filter the input before the query, do we have to format the query using sprinf?


Link to comment
Share on other sites

* Possibly a spelling error, but it's sprintf - but not to worry, that isn't your question.

Sprintf is used to generate formatted strings from one or more arguments. The format argument is a string consisting of normal text and/or special conversion specifications. Conversion specifications begin with a single percent symbol (%). Source.

I personally do not use it, but the ones used on most lines of programming is i think not needed.

Link to comment
Share on other sites

As a_bertrand & sniko said, it's used to format strings.

PHP is a language that's variables are very... vague in definition. That means, you don't have to define your variables before use, and all variables carry a mixed type(unless otherwise defined).

It's not like say C per instance, where you have to define the variables before use and with a type. To sum it up, sprintf() isn't as needed in PHP as in another like C*, so using these type of functions are almost pointless: it just makes you code prettier in my opinion.

* - In C(stdio.h), the function name is actually printf().

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...