Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

explode comma content

General discussions related to php

Moderators: macek, egami, gesf

explode comma content

Postby jasber » Mon Jun 11, 2012 1:13 pm

Hi,

I'm trying to sort other website content from http://hiscore.runescape.com/index_lite.ws?player=cbb

What i wanna to is sort this conntent so every space would be in new line.

2981,2488,526626378
32300,99,21389751
804,99,63941429
39544,99,21603086


Also would be nice to get them in to table (4 rows, 3 colums).
But then again im stuck at exploding the lines, i have tried some exploding ways but none of them works for me :(

1) print_r (explode(" ",$data));

2)$data = explode(",",$data);

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

4) $array = explode(",", $data);


5) $data = explode(",", $data);
echo $data[0];
echo $data[1];

6) $data = explode("\n", $data);
$data = explode(',', $data[0]); {
echo $newline . '<br />';

7) $data = explode(" ",$data);

8) $array = explode(" ", $data);

My current code is like this:


Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>

<body>

<?php
$data = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player=nfsmw142');
echo $data;

$data = explode(" ",$data);

?>

</body>
</html>
jasber
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jun 11, 2012 1:00 pm

Re: explode comma content

Postby ejsexton82 » Tue Jun 12, 2012 2:09 am

Well, if all you want to do is change the "spaces" to "newlines", then this is the easiest solution:

Code: Select all
echo nl2br($data);


If you want to parse the data, then something like this should work:

Code: Select all
$array = array();
$rows = explode("\n",$data);
foreach($rows as $index => $row) {
   $cols = explode(',',$row);
   $array[] = $cols;
}
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: explode comma content

Postby jasber » Tue Jun 12, 2012 5:25 am

Ye thanks for it :)
jasber
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jun 11, 2012 1:00 pm


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.