Jousi Jousi - 1 year ago 67
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download