php - Writing to a file adds weird content at the end of the line -
I am working on a program that parses a text file by a user and then parsed the XML file on the server However, when I write an XML file, I get some text
& amp; #xD; At the end of each line
This text is not in my original text file. I did not even notice it until I opened it to verify the new XML file unless it all Was the material to fix? Has anyone participated before this and if you can tell me whether I am creating and writing my file?
fileUpload.php - These are 3 rows when the user uploads the file.
$ fileName = basename ($ _files ['fileaddress'] ['name']); $ FileContents = file_get_contents ($ _files ['fileaddress'] ['tmp_name']); $ Xml = $ parse-> ParseUnformattedText ($ fileContents); $ ParseedFileName = pathinfo ($ fileName, PATHINFO_FILENAME) ".xml"; File_put_contents ($ parseedFileName, $ xml);
parser.php
function pars unprocessed text ($ InputTest, $ book name = "") {// create book , Volume, text nodes $ book = new SimpleXmlElement ("book & gt; & lt; / book & gt;"); $ Book- & gt; Add Junk ("book name", $ bookName); $ Conj = $ book- & gt; Add Chald ("conj", "X"); $ Block = $ book-> Add Chald ("Segment"); $ Trimmed text = $ this- & gt; Trim new line ($ input text); $ TrimmedText = $ this- & gt; Trim spaces ($ inputText); $ Text = $ block-> Add child ("text", $ trimmed text); $ This- & gt; AddChapterVerse ($ text, "", ""); // Make a list of pconj for the beginning of the file $ pconjs = $ this- & gt; GetPconjList (); // XML to $ xml = $ book- & gt; Convert asXml () string; // combine the list of pconj and xml strings $ xml = "$ pconjs \ n $ xml"; Return $ xml; }
Input text file
1: 1x I also liked, x was the correct understanding of everyone To write a systematic account, [most] excellent Thifilius and 1: 4 that you can know the certainty of the things in which you were given 1: 5X instructions, in the days of Herod, a priest named Judea and Zechariah X , Who was his wife, belonged to Aaron's daughters and his name was Elizabeth. 1: 8 So it was, that when he was serving as priest 1: 9 before God 1: 9 in the order of his division, 1:10 and all the people of the people were praying outside the sun, But that was why it was done.
and #xD;
The ASCII character is \ r \ n
which is not correctly exiting from parseUnformattedText ()
.
Try $ xml = nl2br ($ parser -> parseUnformattedText ($ fileContents));
Comments
Post a Comment