468,315 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

printing a string with % using sprintf

Hi All

I'm having problems printing a string with a % char. Here is the code

line = sprintf("<table width=100% id=%s>\n", $table_id);

I'm getting an not enough parameter error. The % for the 100% is being
mis interepreted as a format char. Though i worked around by coding it
line = sprintf("<table width=100%s id=%s>\n", '%', $table_id);, i think
there should be a way with which the % can be escaped PHP.

The PHP documention does not have any info about this. if anyone has
come accross such problems and found a work around, please help me out.

Thanks
/V
Jul 17 '05 #1
6 2424
Double % sign.

sprintf("<table width='100%%' id='%s'>\n", $table_id);

-Jay
Venkat Venkataraju wrote:
Hi All

I'm having problems printing a string with a % char. Here is the code

line = sprintf("<table width=100% id=%s>\n", $table_id);

I'm getting an not enough parameter error. The % for the 100% is being
mis interepreted as a format char. Though i worked around by coding it
line = sprintf("<table width=100%s id=%s>\n", '%', $table_id);, i think
there should be a way with which the % can be escaped PHP.

The PHP documention does not have any info about this. if anyone has
come accross such problems and found a work around, please help me out.

Thanks
/V


Jul 17 '05 #2

Jay Moore wrote:
Double % sign.

sprintf("<table width='100%%' id='%s'>\n", $table_id);

doesn't seems to work. it still asks for more parms. i also did \%, but
it is not working either.

/V
Jul 17 '05 #3


Venkat Venkataraju wrote:

Jay Moore wrote:
Double % sign.

sprintf("<table width='100%%' id='%s'>\n", $table_id);

doesn't seems to work. it still asks for more parms. i also did \%, but
it is not working either.

/V


Works just fine for me. Make sure you don't have any typos.

-Jay

Jul 17 '05 #4
Venkat Venkataraju wrote:
Hi All

I'm having problems printing a string with a % char. Here is the code

line = sprintf("<table width=100% id=%s>\n", $table_id);

I'm getting an not enough parameter error. The % for the 100% is being
mis interepreted as a format char. Though i worked around by coding it
line = sprintf("<table width=100%s id=%s>\n", '%', $table_id);, i think
there should be a way with which the % can be escaped PHP.

The PHP documention does not have any info about this. if anyone has
come accross such problems and found a work around, please help me out.

Thanks
/V


If it's anything like C++ (as PHP usually is), and if I remember my c++
correctly, it's going to be %%. Try that.

-- Inuyasha4Life
Jul 17 '05 #5
In message <h1*********************@newssvr28.news.prodigy.co m>, Venkat
Venkataraju <segfault@?.?.invalid> writes
Hi All

I'm having problems printing a string with a % char. Here is the code

line = sprintf("<table width=100% id=%s>\n", $table_id);

I'm getting an not enough parameter error. The % for the 100% is being
mis interepreted as a format char. Though i worked around by coding it
line = sprintf("<table width=100%s id=%s>\n", '%', $table_id);, i think
there should be a way with which the % can be escaped PHP.

The PHP documention does not have any info about this. if anyone has
come accross such problems and found a work around, please help me
out.


You have a percent literal in the line. You can just concatenate it:

line = "<table width=100% id=" . $tableid . ">\n";

--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #6
Venkat Venkataraju <segfault\"@\"nospam.sbcglobal.net> wrote:
line = sprintf("<table width=100% id=%s>\n", $table_id);


This will work:

line = sprintf("<table width=100%s id=%s>\n", '%', $table_id);
--
Spam is spam no matter who's doing it or for what reason.

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Illuzioner | last post: by
3 posts views Thread by huey_jiang | last post: by
42 posts views Thread by junky_fellow | last post: by
9 posts views Thread by Neal Barney | last post: by
13 posts views Thread by bwaichu | last post: by
5 posts views Thread by 2b|!2b==? | last post: by
41 posts views Thread by nospam | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.