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.
Explode inserts spaces between each character in string
Collapse
X
-
Tags: None
-
Originally posted by need2know2I'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.
can you share us the script so that we can figure out what's wrong.
bonski -
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]RonaldComment
-
Thanks for the replies.
Here's the code
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>"; }
Code:$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++; }
Comment
-
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 repliesComment
-
Originally posted by need2know2I have spaces between every characterComment
Comment