472,982 Members | 1,091 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2618
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Illuzioner | last post by:
hey all, can anyone enlighten me on the proper c++ way to print formatted text into a string? e.g. string mytext; double nn=445566.332211;
3
by: huey_jiang | last post by:
Hi All, I am trying to figure out a right syntax to convert an integer array into hex array. sprintf worked for me on doing single integer: int i, Iarray, n=15; char buf; sprintf(buf,...
42
by: junky_fellow | last post by:
Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is...
12
by: babak | last post by:
Hi everyone I want to format a string (using sprintf) and put it in a messagebox but however I try to do it, it doesn't seem to work. Here is an example sample of what i try to do: char msg;...
9
by: Neal Barney | last post by:
I have a C program which runs on a device using a Zilog Z180 microprocessor. While it can address 1MB of RAM, it can only address 64KB at any given time. And of that only 16KB can be used for...
13
by: bwaichu | last post by:
Now, I read the faq, and it suggests using sprintf. However, I want to all ways know where the integer finishes in the string. Basically, I want to: nbr | other data But the other data all...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
5
by: 2b|!2b==? | last post by:
I am not making much progress porting some old C code to C++ ... I am porting the lines below, which prints an ISO8601 date string: char buff ; memset(buff, '\0',16);...
41
by: nospam | last post by:
If I have a string say: myvar = "This is a string"; How do I use sprintf to convert the string so it has 4 spaces padded on the left like:
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.