473,322 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

sprintf with dynamic number of elements

I'm looking for a way to pass a dynamic number of args to sprintf.

So instead of

$a = "a";
$b = "b";
$c = "c";
sprintf($format, $a, $b, $c)

one could

$args = array("a", "b", "c");
sprintf($format, $args)

It seems like sprintf should support this natively, but it doesn't.

Is there a way to accomplish this?
Nov 28 '06 #1
3 2329
Bosconian:
Is there a way to accomplish this?
I'd be guessing spontaneously this way

$args = array("a", "b", "c");
sprintf($format, extract($args))

Rgds
--
Nov 28 '06 #2
..oO(Bosconian)
>I'm looking for a way to pass a dynamic number of args to sprintf.
[...]
http://www.php.net/vsprintf

Micha
Nov 28 '06 #3
"ljb" <lb****@pobox.com.xxxxxwrote in message
news:T6*****************@newsread3.news.pas.earthl ink.net...
ne*****@gmx.de wrote:
>.oO(Bosconian)
>>>I'm looking for a way to pass a dynamic number of args to sprintf.
[...]

http://www.php.net/vsprintf

As stated above, vsprintf() is the answer in this case. In other cases,
you can use call_user_func_array() if you need to pass a variable number
of
arguments to a function.
I totally missed vsprintf() *blush*

Leave it to the PHP developers for thinking of EVERYTHING.

Anyway, sorry for wasting your time. I had previously visited the sprintf()
page, but overlooked vsprintf() for whatever reason.
Nov 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pilatus | last post by:
Hi everybody, I am beginner and I have a problem in this simple code : I want that the char contents 01234567, but it don't work Could you help me ? int bin ; char *buf = new char ; for (int...
13
by: Yodai | last post by:
Hi all.... I have a little problem that's driving me nuts. I can't seem to make any sense of it. I have this small webserver that substitutes some data from a page when finds a substitution...
11
by: D | last post by:
hi, i would like to know how to calculate the size of a dynamic array created using a dereference declaration like int *numbers and allocating via malloc or calloc: numbers=(int...
9
by: Matt Garman | last post by:
I'm trying to develop (for my own personal use) a general "messaging facility" in C. The idea is that the facility will be used for both debugging/logging and user interfacing. I'd like it to be...
14
by: chai | last post by:
Can anyone help me in finding elements stored in a dynamic array in.
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
173
by: Ron Ford | last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use MS's Visual C++ Express and use its C capability. In the past with my MS products, I've simply needed to make .c the...
2
by: Damir | last post by:
Hello! I have noticed that after (sucessfully) executing the command: FLUSH PACKAGE CACHE DYNAMIC the dynamic SQL statement cache is not completely cleared (some of the dynamic SQL statement...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.