Jousi Jousi - 2 months ago 9
HTML Question

Converting a txt file to string, then to array and then printing each word of the array

I am trying to convert a text file into a string, then into an array and then finaly print each of the values (words) into separate 'a' holders.

The .txt file contains one line of text.

I have tried it through a for loop, like so:

$lines = file_get_contents('test.txt', FILE_USE_INCLUDE_PATH);
$words = explode(" ", $lines);

for ($x = 1; $x >= 100; $x++){
print '<a id="word$x">'$words[$x]'</a>';

But that doesnt work. I am sure that I am just missing something basic, but I have tried and failed so many times, that I need others opinions and advice.


At first, don't forget about string concatenation: print '<a id="word'.$x.'">'.$words[$x].'</a>';

If you need more, than only 100 words use $x < count($words) in your for