Jump to content
MakeWebGames

Recommended Posts

Posted

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?

Thanks

Posted

* 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.

Posted

sprintf can be avoided in nearly all PHP code specially if you use it to sanitize parameters for SQL queries. Use it purely to format things which needs to be stored in strings, like for reports. For other needs you should use other means.

Posted

If from mwg then chances are no, you don't need it. The site went through a “omg sprintf() can do everything, and make everything secure” phase. In old mods is very over used.

Posted

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().

Join the conversation

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

Guest
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...