Php:get first word from text file

floppy -  
 floppy -
Hello,

Here is my problem.

I need to retrieve the first word written in a text file using PHP.

I can't find out how to do it.
Can someone please give me a function to use?

Thank you in advance...

Configuration: Windows 7 / Internet Explorer 8.0

2 answers

Luxerails Posted messages 160 Registration date   Status Member Last intervention   41
 
Assuming that the words are separated by spaces... (like in a normal sentence) we can do:
explode(' ', $text);


For example:
$text = file_get_contents('file.txt'); $e = explode(' ', $text); $first_word = $e[0];


Here $e is an array that contains each word, for example by doing
$e = explode(' ', 'this is a sentence');


We have $e[0] = 'this', 1 = 'is', 2 = 'a' and 3 ='sentence'
18
floppy
 
Impeccable!!!!!!!!!!!!!!
Thank you very much...
0