first off I’m a noob to PHP but here is my problem. I am trying to read a line from a text file, manipulate the line then write the original and new line to a new text file. For some reason it adds an extra return or new line in the output file.
Original File Text
/Volumes/EC/EC_0101/B-W Art/001_0101.EPS
...
/Volumes/EC/EC_0101/B-W Art/010_0101.EPS
HTML Output for Testing
EC:EC_0101:B-W Art:001_0101.EPS EC EC_0101 B-W Art 001_0101.EPS
...
EC:EC_0101:B-W Art:010_0101.EPS EC EC_0101 B-W Art 010_0101.EPS
New Text File Output
EC:EC_0101:B-W Art:001_0101.EPS
EC EC_0101 B-W Art 001_0101.EPS
...
EC:EC_0101:B-W Art:010_0101.EPS
EC EC_0101 B-W Art 010_0101.EPS
Should be tab delimited
EC:EC_0101:B-W Art:001_0101.EPS EC EC_0101 B-W Art 001_0101.EPS
...
EC:EC_0101:B-W Art:010_0101.EPS EC EC_0101 B-W Art 010_0101.EPS
My Code
$file = fopen("files_list.txt", "r") or exit("Unable to open file!");
$filename = "files_list_tab.txt";
//Output a line of the file until the end is reached
while(!feof($file))
{
$strLink = fgets($file);
//$strComment = $strLink;
$strLink= str_replace("/",":",$strLink);
$strLink= str_replace(":Volumes:","",$strLink);
$strComment= str_replace(":","\t",$strLink);
$strCombined = $strLink."\t".$strComment;
$array[] = $strCombined;
echo $strCombined. "<br>";
}
fclose($file);
echo "Done <br>";
$strCombined = $array;
file_put_contents($filename, $strCombined);
echo "Done <br>";
Try: