473,388 Members | 1,526 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,388 software developers and data experts.

Appending an integer to a string

I am having problems appending a number to the end of a string. I
searched google and google forums and couldn't figure it out .... sorry
i'm sure its simple.

so I have:

$filename = 'test.file.";
$i = 0;

and I want to change $filename to become 'test.file.0'.

$filename .= $i; //doesn't work
$filename += $i; //doesn't work
$filename .= (string) $i; //doesn't work, nor does += (string) $i

So, how could I do this using these variables?

(I plan to do this inside a loop, and loop until test.file.i does not
exist, at which point I will create one and save the news post. I will
do the same to display the news on my front page -- loop through
starting at i=0 and display the contents of the files until test.file.i
does not exist)

Cheers,
-Rob

Oct 7 '05 #1
2 1597
I am having problems appending a number to the end of a string. I $filename = 'test.file.";
$i = 0; and I want to change $filename to become 'test.file.0'.


$filename = "$filename$i";

or

$filename .= "$i";

or

$filename .= strval( $i );

or

$filename = sprintf( "%s%d", $filename, $i );

or

google some more...

---
Steve

Oct 7 '05 #2
Robizzle (Ro********@gmail.com) wrote:
: I am having problems appending a number to the end of a string. I
: searched google and google forums and couldn't figure it out .... sorry
: i'm sure its simple.

: so I have:

: $filename = 'test.file.";
^

Mismatched quotes. It works for me when I use the correct quotes.

$ php

<?php

$filename = 'test.file.'; # note quote
$i=0;

$filename .= $i;

echo $filename;

?>
^D

test.file.0


--

This programmer available for rent.
Oct 7 '05 #3

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

Similar topics

0
by: Jared | last post by:
Hello all, I'm looking for the best way to wrap my cell contents in a html label tag. The results I'm looking for will allow the user to select the checkbox when any cell in the tablerow is...
4
by: John A Grandy | last post by:
could someone explain the following to me : Appending the literal type character I to a literal forces it to the Integer data type. Appending the identifier type character % to any identifier...
3
by: Donald Grove | last post by:
Is it possible to append records to a space delimited text file, using Access 2000?
9
by: al jones | last post by:
Sorry, it's getting late and I'm tired. I'm trying to fill a richtect box with text derived from the array I was asking about earlier (thank you). I'm not sure what I'm seeing - since most of...
3
by: Jacob.Bruxer | last post by:
Hi, I want to be able to append text using a For loop to each textbox in an array of textboxes that I've created, called tBoxes(). Basically I want to add a number of spaces to each textbox in...
2
by: mamin | last post by:
I have a table that I need to export out to a text fiel, without column headers. I also need to have the file name include currernt date. Can anyone help me? I'm using the following code: ...
6
by: Thorben Grosser | last post by:
Hello Newsgroup, at the moment I am coding an archive database for a bank. Every folder has an own number, following the sheme x-x-xxx-yyyy whereas x-x-xxx describes the archive, the storage...
5
by: flavourofbru | last post by:
Hi, Is it possible to add an int or a string or a char to a vector variable?? For example if I declare a vector variable as follows: vector<string> abc; Can I append an integer value or some...
0
by: nbardach | last post by:
Hope this finds everyone well. Happy New Year! I'm trying to build a Loop for a set of dropdown menus I'm inserting into a form. Basically, the client has to be able to select 1 to 20 donors...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.