This question already has an answer here:
I am a beginner with PHP code and I'm trying to figure out how to use a variable inside a file_get_contents.
I have an array of names that are associated with textfiles in a certain folder. I am trying to use the name in the array to print out the text file.
echo '<p>';
echo nl2br(file_get_contents( "Files/"+$names[1]+".txt"));
echo '</p>';
</div>
In order to concatenate php variables with string, you need to use dot operator. In your case, the second line of code should be:
echo nl2br(file_get_contents( "Files/" . $names[1] . ".txt"));