html - PHP string operations lose newline characters -
I am writing a script in PHP to change some code in HTML files. Every file will be read in line per line And thus every operation should be per line. My problem is that some operations lose the new line if it is the end of the file.
Just to be clear, I want to get new characters in the HTML ( Example of the first HTML: Example of HTML after this: How should this happen: PHP code: Even if I use the What works when I close this new device later: So whenever there is something after adding a new line, it will work whether the new line Is it possible to work without adding new material? Take a look at this UPDATE I tried your code and it requires some additional new line characters. Works fine with See this code: & lt; br / & gt; ) but to get a better format code inside the code editor, Newline characters (
\ n ) are required.
& lt; body & gt; & Lt; Div id = "wrapper" & gt;
& lt; body & gt; & Lt; Div id = "jobtempl" & gt; & Lt ;! - JobTemple - & gt; & Lt; Div id = "wrapper" & gt;
& lt; body & gt; & Lt; Div id = "jobtempl" & gt; & Lt ;! - jobtempl - & gt; & Lt; Div id = "wrapper" & gt;
Change the personal function resource ($ file) {$ this- & gt; File = $ file; $ Lines = file ($ -> -; // to get some $ $ bodyStartLine as line number, where to add $ handle = fopen ($ this- & gt; file, 'w'); Currency ($ line as line $) {if ($ i == $ bodyStartLine) {$ line = $ line '& lt; div id = "jobtapple"> gt; & lt;! - jobtempl - & gt; ;} If ($ i == $ bodyEndLine) {$ line = '& lt; / div & gt; & lt ;! - / jobtempl - & gt; PHP_EOL $ line; // works} Fwrite ($ Handle, $ line);} fclose ($ handle);}
$ line = $ line '& lt; div id = "JobTemple" & gt; & lt ;! - Jobtempl ->. \ "\ N"; This does not work for implementing a new line
\ r \ n \ and
\ r \ / code>
$ line = '& lt; / div & gt;
echo 'hello, world!' . "\ XA";
PHP_EOL and
\ xA .
Comments
Post a Comment