file("blog.txt"); the file() function reads a file into an array of strings but the \r\n are left at the end of each line so your $fileContents[$i] content an \r\n Note: if working on unix like system only a \n is added at each line end So you have to put off the 2 caracters \r\n ( or only...