views:

111

answers:

1

Hi,

I'm trying to parse the output of this page -> http://master.anti3d.com/raw_server_list2.php

The documentation of that master server says that every entry is separated in this way

Note: LF = LineFeed = 10

Format: serverName[LF]ipAddress:port;users/maxusers;gameCount;version;location[LF]

Example:

Server Name1

111.111.111.1111:27888;0/25;0.86;USA

Server Name2

222.222.222.2222:27888;0/50;0.86;Canada

so I'm using OOCurl library for retrieving the site data using object oriented CURL

<?php

include_once('oocurl.php');

$fetchmaster = new Curl('http://master.anti3d.com/raw_server_list2.php');
$data = $fetchmaster->exec();
$parsedata = explode('\n', $data);
print_r($parsedata);
?>

Curl retrieves the page info but when I try to explode using \n character or newline, ASCII 10, it just doesn't works. I downloaded the page output and saw it with an hex editor and it's using \x0a, \n, linefeed

what am I doing wrong?

+9  A: 

Change the single quotes in

$parsedata = explode('\n', $data);

to double quotes to properly encode a newline.

$parsedata = explode("\n", $data);

For example:

print '\n'; // prints a backslash, followed by the letter n
print "\n"; // prints a newline

Strings in the PHP Manual:

Note: Unlike the two other syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

John Douthat
omg that worked :D thanks
Korrupzion
then maybe mark it as the accepted answer
adam