I'm filling an array with explode(";" $linetoread) and then using the array to write to a file. When I open the file the array elements have spaces between each character. I've tried split as well with the same results. If viewed in a browser, all the spaces are missing even though they exist in the source.
8 2496
I'm filling an array with explode(";" $linetoread) and then using the array to write to a file. When I open the file the array elements have spaces between each character. I've tried split as well with the same results. If viewed in a browser, all the spaces are missing even though they exist in the source.
hi there,
can you share us the script so that we can figure out what's wrong.
bonski
try using the trim($variable) ; function to trim out all the spaces.
Trim() does not remove embedded blanks, just the white space at start and end of a vriable. To remove embedded blanks combine trim() with a reg exp like[php]$string = trim (preg_replace ('`[\s]+`', ' ', $string));[/php]Ronald
Thanks for the replies.
Here's the code -
// File to copy from
-
$fSourcePath = "HCFD-SM.xml";
-
$fSourceHandle = fopen($fSourcePath, 'r');
-
-
//File to copy to
-
$fTargetPath = "test.txt";
-
$fTargetHandle = fopen($fTargetPath, 'w');
-
-
//MP3Tag file
-
$fMP3Source = "mp3tag.csv";
-
$fMP3Handle = fopen($fMP3Source, 'r');
-
-
-
$thisLine = fgets($fMP3Handle);
-
$thisLine = fgets($fMP3Handle);
-
$arrMP3 = explode(";", $thisLine);
-
-
-
for($i=0;$i<count($arrMP3);$i++)
-
{
-
echo $arrMP3[$i] . "<br>";
-
}
-
Viewed in the browser it looks fine. But then I write to the file: - $currentLine = 0;
-
$lineCount = count($arrMP3);
-
while($currentLine < $lineCount)
-
{
-
fwrite($fTargetHandle, $arrFile[$currentLine]);
-
if(trim($arrFile[$currentLine]) == "</itunes:owner>")
-
{
-
fwrite($fTargetHandle, " <item>\r\n");
-
fwrite($fTargetHandle, " <title>" . $title . "</title>\r\n");
-
fwrite($fTargetHandle, " <link>" . $path . $filename . "</link>\r\n");
-
-
// etc
-
// etc
-
fwrite($fTargetHandle, " </item\r\n");
-
}
-
$currentLine++;
-
}
I have spaces between every character
It seems that variables $title, $path and $filename have not been initialized.
Satas you are correct. Those files are not initialized because I pasted in old code in which I was using a list rather than an array
All the fwrites are actually using the array elements created with explode(...)
Unfortunately, both ways produce the spaces in the strings
ronverdonk - your solution would work if I didn't have spaces in some of the strings that I want to keep...
Thanks for the replies
Those files are not initialized because I pasted in old code in which I was using a list rather than an array
Could you provide us working, not "old" code?
hsriat 1,654
Recognized Expert Top Contributor
I have spaces between every character
If the spaces are between all the characters of the file ( including XML tags ie. <item> is displayed as < i t e m >), then you got to do something with the file encoding. That's not explode's mischief.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark |
last post by:
Hello,
I have been searching for a reason for this behavior but no solution
so I figured I would ask.
Basically I have a web page that displays data in a database to the
user for updates/deletion/addition. For each data field ont he web
page I put the data from the database in the field name with teh field
name and data seperated by a |. ex: address|35 Elm St.
|
by: William Krick |
last post by:
I have a string containing concatenated ascii "records" that are each
terminated by '\n'.
For testing purposes, I construct sample data like this...
$mystring = "a|b|c|d\n"."e|f|g|h\n"."i|j|k|l\n"."m|n|o|p\n";
I want to use explode() to put the records into an array like this...
|
by: Riddler |
last post by:
Anyone have an idea about how I could go about writing a function that
would simply insert a character inbetween each character in a string?
For instance:
HELLO WORLD
would turn into:
H E L L O W O R L D
|
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it will split myString up using the delimiter of 1 space
so that
|
by: Jonathan Ng |
last post by:
Hi,
I was wondering if there was a way to include the white spaces in a string.
Currently, I am using:
scanf("%s", &input);
However, this doesn't include the 'space' character or any other white
spaces. Is there a way I can include the 'space' character rather than skip
in.
| |
by: FFMG |
last post by:
Hi,
I need the php equivalent of explode in one of my app.
I read a very big file and "explode" each line to fill a structure.
The reading of the file, 19Mb, (I will also need to streamline the way
I read each line I guess), takes about 10 seconds. But when I 'explode'
each line the process takes about 140 seconds.
This is what I have tried so far...
|
by: Joe |
last post by:
I have a 'random quotes' plugin that I use which reads tab delimited
quotes from multiple text files in a directory, and then randomly
displays one. Each text file contains multiple lines, each listing a
person and a quote, separated by a tab, and each file is based around a
topic. I use fopen and fread to suck in all the text, and then explode
to separate into an array of names and quotes. It is working fine with
one small exception. When...
|
by: DanielJohnson |
last post by:
I am writing a program in which I am removing all the spaces from the
string. I thought that I could do it two ways. One was parsing the
string character by character and copying onto another output string.
But this was trivial.
The other option is to use pointers and shift all the characters after
the space by one space to the left. I did this program using pointers
and then using array too and I get segmentation fault. What is going...
|
by: micronack |
last post by:
{NOTE . = space}
I made a script to allow me to edit my webpages online through a text area in my cgi script but I've run into a problem. For whatever reason the text area seems to put spaces in front of each line {except for the first} so,
line one
line two
line three
becomes
line one
.line two
.line three
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |