Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is it starting a new line before it should in PHP array?
    primarykey
    data
    text
    <p>I'm having a problem with arrays and file writing, what I want to do is take one file, and copy it onto another file, except with formatting added to it. </p> <p>To be specific, this:</p> <p>Line 1<br> Line 2<br> Line 3 </p> <p>Would become this:</p> <pre><code>&lt;br /&gt;&lt;hr /&gt;Line 1 &lt;br /&gt;&lt;hr /&gt;Line 2 &lt;br /&gt;&lt;hr /&gt;Line 3 </code></pre> <p>And I've sorta done that, but something weird happens. Instead of formatting all on one line, it linebreaks and keeps going. Like this </p> <pre><code>&lt;br /&gt;1 THE END&lt;br /&gt;7 THE END&lt;br /&gt;0 THE END&lt;br /&gt;Red THE END&lt;br /&gt;Silent THE END&lt;br /&gt;No ChangesTHE END </code></pre> <p>My code for this is:</p> <pre><code>&lt;?php $filename1 = "directorx_OLDONE.txt"; $filename2 = "directorx_NEWONE.txt"; $file1 = fopen($filename1, "r") or exit ("No"); $file2 = fopen($filename2, "w") or exit ("No"); while (!feof($file1)){ $listArrayf1[] = fgets($file1); } fclose($file1); echo var_dump($listArrayf1) . "&lt;br /&gt;&lt;br /&gt;"; $entries = count($listArrayf1) - 1; echo $entries; for($i=0;$i&lt;=$entries;$i++){ $listArrayf2[] = "&lt;br /&gt;".$listArrayf1[$i]."THE END"; fwrite($file2, $listArrayf2[$i]); } fclose($file2); echo var_dump($listArrayf2); /* Open file1, r Open file2, w While it's not the end of the file, add each line of file1 to an array. Count the number of lines in file1 and call it Entries. -1 because gotta start at 0. Make a new array with the values of the old one, but with tags before and after it. */ ?&gt; </code></pre> <p>I'm sure there's a better way to accomplish the ultimate goal I'm trying, which is detecting certain words entered into a form, (There's probably a better way than making a formatted and non-formatted copy of what gets entered.) but my PHP vocab is limited and I'd like to figure out the long, prerequisite hard ways before learning how to do em easier.</p> <p>At first I thought that it was because I was writing the OLDFILE manually, using the return key. So I made a script to write it using \n instead and it changed nothing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload