/    Sign up×
Community /Pin to ProfileBookmark

sprintf() & print()

Folks,

Just came across sprintf() but I don’t see difference between it and the printf().

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 06.2021 — https://www.php.net/sprintf
> Returns a string produced according to the formatting string _(Translation: the resulting string is returned, which you can assign to a variable to output later or to use in another function, etc.)_

https://www.php.net/printf
> Produces output according to format. _(Translation, it outputs the result immediately, like an echo would)_
Copy linkTweet thisAlerts:
@developer_webauthorFeb 11.2021 — @NogDog#1627691

Mmm. I think I understand what you mean.

Sometimes I see functions with a third Param where the function's data is returned and dumped into the $var that is in the function's 3rd param we mention.

Right ?

You know what, I would understand more with your code samples than the ones in the PHP manual.

Cheers!
Copy linkTweet thisAlerts:
@VITSUSAFeb 12.2021 — @developer_web#1627671 printf("format", args) is used to print the data onto the standard output which is often a computer monitor.

sprintf(char *, "format", args) is like printf. Instead of displaying the formated string on the standard output i.e. a monitor, it stores the formated data in a string pointed to by the char pointer (the very first parameter). The string location is the only difference between printf and sprint syntax.
Copy linkTweet thisAlerts:
@developer_webauthorFeb 12.2021 — @VITSUSA#1627877

Ok. I will bear this in mind when revising on print and print and sprintf. I usually use echo and die to print on screen. Hence forget about the others. Forget their params.
Copy linkTweet thisAlerts:
@HarshShahFeb 17.2021 — print() is used to print character stream of data on stdout console and sprintf() is used to store data on character buffer instead of printing on console. This character buffer is specified in sprintf.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...