hi im back again.......i have a code to create strings and save it within a text file to pass variables to flash. im using the string format below. -
mylist=apple,cherry,lemon,banana&mylist2=apple,cherry,lemon,banana
-
this code below is what im using to write my string to the text file, basically the info is collected from a db and i use a loop to cycle through and write each value in. I have to seperate these values using a comma ',' like in my above example. i can do this but then i am left with a comma at the end of my string before the next variable starts like this mylist=apple,ch erry,lemon,bana na,&
is there a way to add commas and once it gets to the last value to write to get php to check that its the last value and not add a comma in? -
$file = "upload/$random_digit/gallery.txt";
-
$imgHandle = fopen($file, 'w') or die("can't open file");
-
-
$iv= 1;
-
$lQ = ',';
-
-
$stringData = "&imgLoc=";
-
fwrite($imgHandle, $stringData);
-
-
for($i=0;$i<$totalRecords;$i++)
-
{
-
$stringData = $returnedData[$i]["imageLoc"] .$lQ ;
-
fwrite($imgHandle, $stringData);
-
}
-
-
fclose($imgHandle);
-
4 4324
yeah i had a look at that....it's basically the same as str_replace.... i've used str_replace and it works great.....thank s for the advice it is something i'm looking into in more detail
code green 1,726
Recognized Expert Top Contributor
I would improve the efficiency drastically by concatenating then writing one big string.
Then you can easily trim the last comma - $file = "upload/$random_digit/gallery.txt";
-
$imgHandle = fopen($file, 'w') or die("can't open file");
-
$iv= 1;
-
$lQ = ',';
-
$stringData = "&imgLoc=";
-
for($i=0;$i<$totalRecords;$i++)
-
{
-
$stringData .= $returnedData[$i]["imageLoc"] .$lQ ;
-
}
-
$stringData = rtrim($stringData,',');
-
fwrite($imgHandle, $stringData);
-
fclose($imgHandle);
-
Even if this causes memory problems due to a huge string I would still do the same but split into chunks
that's exactly what i have done.....the speed it does it in is good and it doesn't take much memory.....i basically build the string and at the end i str_replace the unwanted commas then save it back into the file
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: !TG |
last post by:
I currently use Do while loop, but I'd rather use a For Loop though I
have never gotten the hang of them.
Would some one please be so kind as to show me how to loop through a
recordset.
|
by: cs |
last post by:
if i have
typedef struct{
unsigned a;
unsigned *b;
}tp;
i would like to ask if it is ok for the "C standard 89" doing
something like this
{
|
by: Ivan V via DotNetMonster.com |
last post by:
Hi All:
I would like to know if I can loop my selection in a combobox. For
instance, I got 8 items in a combobox, and when I selected it using the up
and down arrow, it will stop in the first record even I keep on press the up
arrow, on the other hand, if it's the last selection, it will stop in the
last record even I keep on press the down...
|
by: sumit1680 |
last post by:
Hi everyone,
I am using the below listed code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
|
by: tshad |
last post by:
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in RaceCarCollection)
{
...
if last row do something?
}
| |
by: Xean45 |
last post by:
Hey all,
Sorry to be the noob with two posts asking a question, but I've been fighting with this for a couple days now, and as far as I can tell, this should be working, but PHP isn't my main language, so I'm sure there's something being missed.
I've made a small program that allows the user to first select a country, then a state/province,...
|
by: kcdoell |
last post by:
Hello I have a code where I want to delete the records that are found in my DAO recordset. I took a stab at this for the first time and got it to work but it is only delete one record at a time. If I execute the code again my record count will be minus one and then it will delete another single record etc etc until there are no records to...
|
by: shivapadma |
last post by:
1.i am just trying to insert a "structure record" into a file using fwrite() function by the following code
2.
#include<stdio.h>
#include<conio.h>
struct student
{
char name;
int rollno;
};
|
by: Abubakar |
last post by:
Hi,
recently some C programmer told me that using fwrite/fopen functions
are not efficient because the output that they do to the file is
actually buffered and gets late in writing. Is that true?
regards,
...ab
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |