Get and split in php text from text-file

User avatar
JanMolendijk
Posts: 71
Location: Holland Rotterdam

Get and split in php text from text-file

Dear Admin i`m back again with something new...
How can i show into a php document text from an text-file ?

i have this code into the text file
name: poll_result
My text is:

Code: Select all

184||2

Factly i would like to see only the score 184 or the 2
but i`m also happy with both results (whole)

Admin
Hello,
You can use file_get_contents() to get a string with file data.
Then, with explode() you can split that string by the separator you want, and store the resulted items into an array.
- Here is a code example:

Code: Select all

$file ='path_to/filename'; //path to the text file
$fdata = file_get_contents($file); //get file data
$fdata = explode('||', $fdata); //split text data by '||', results into an array

//show data from 1st and 2nd item
echo $fdata[0];
echo '<br>'. $fdata[1];

Adv. Posts: 01

Similar Topics