SHAD Posted May 2, 2011 Share Posted May 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted May 2, 2011 Share Posted May 2, 2011 * 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. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted May 2, 2011 Share Posted May 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Dominion Posted May 2, 2011 Share Posted May 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted May 3, 2011 Share Posted May 3, 2011 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(). Quote Link to comment Share on other sites More sharing options...
SHAD Posted May 3, 2011 Author Share Posted May 3, 2011 Thanks for your replys guys, personally i hate the use of sprintf, it's why i asked this question about it been needed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.