Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP, problem with explode()

Name: Anonymous 2011-08-08 9:20

So I have a text file containing lines of stuff. I get a line from the file, for example this one:
2   88.115.209.176      -t3>SJ                  Red     21      21      10      0       3       0       3

I place that to a variable $lineoftext, and then explode() it by whitespace.

$parts = explode(" ", $lineoftext);

The output?
$parts[0] = 2
$parts[1] = 88.115.209.176      -t3>SJ                  Red     21      21      10      0       3       0       3

What am I doing wrong here?

Name: Anonymous 2011-08-08 9:41

$lineoftext = '2   88.115.209.176      -t3>SJ                  Red     21      21      10      0       3       0       3';
$parts = explode(" ", $lineoftext);

print_r($parts);

Works fine for me.

Name: Anonymous 2011-08-08 10:53

$str = preg_replace('/[\s]+/', ' ', $str);

Name: Anonymous 2011-08-08 13:08

To actually answer the question:

You only have 1 space in the line of text your trying to parse, and that's in between "2" and "88.115.209.176". The rest of it appears to be tabbed; therefore, does not propagate an array the way your wanting it to. Try:

$lineoftext = str_replace("\t"," ",$lineoftext);
$parts = explode(" ", $lineoftext);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List