deepu sankar
deepu sankar

Reputation: 4455

explode function not working properly

$filename = 'itunes_report.txt';
$f = fopen($filename, 'r');
$db = array();
$dbSize = 0;

$var = file($filename);
$mydata = trim($var[1]);
$temp   = explode(" ", $mydata);
print_r($temp);

i read data from a file using this code. i was take the first line from the text file. this is the line

APPLE   US  ebookReaderipad EC Media (International) Pvt. ltd   BooksOnwink 1.3 1F  1   0   07/30/2012  08/05/2012  GBP GB  GBP 425105344   0

i explode this line using white spaces. Then some white spaces are missing in output. out put

Array ( [0] => APPLE    US  ebookReaderipad EC [1] => Media [2] => (International) [3] => Pvt. [4] => ltd   BooksOnwink 1.3 1F  1   0   07/30/2012  08/05/2012  GBP GB  GBP 425105344   0 )

Upvotes: 2

Views: 2177

Answers (1)

complex857
complex857

Reputation: 20753

Your input seem to be is tab \t delimited, you can split on "\t":

$temp = explode("\t", $mydata);

or if you are really mean to split on every whitespace, try using a more flexible spit with regexps:

$temp = preg_split('/\s+/', $mydata);

This will split on everything considered whitespace and consume sequence of whitespaces too.

Upvotes: 5

Related Questions