Page 1 of 1

string to an array

Posted: Fri Dec 29, 2006 2:36 pm
by SidewinderX
Well I've done this

Code: Select all

ob_start();
include("$nukeurl/modules/$vwar_modulename/extra/nextactions.php");
$output = ob_get_contents();
ob_end_clean();
echo $output;
and the i get the contents of the page as a string stored as $output. When displayed it is displayed as 5 lines of content, for example
sTs vs. -BH- 30-12-06 at 9:00 pm
sTs vs. HSK 6-1-07 at 9:00 pm
sTs vs. LoD 7-1-07 at 8:00 pm
sTs vs. LoD 13-1-07 at 9:00 pm
sTs vs. UNP 14-1-07 at 3:00 pm
The names, dates, and times are not static. I was wondering what function I could use to make each line an element of an array. That way I could reference
sTs vs. -BH- 30-12-06 at 9:00 pm
as

Code: Select all

date[0]
or something similar. :D

Posted: Fri Dec 29, 2006 2:39 pm
by richmix
Does the HTML source look like that, or the final outputted and processed page?

Posted: Fri Dec 29, 2006 2:39 pm
by John Cartwright
hrmm, try

Code: Select all

$date = file($nukeurl.'/modules/'.$vwar_modulename.'/extra/nextactions.php');

Posted: Fri Dec 29, 2006 2:44 pm
by richmix
Just figure out what characters are causing the line breaks (\n or <br />) and use an explode().

Code: Select all

$date = explode("<br />", $output);
No?

Posted: Fri Dec 29, 2006 2:49 pm
by SidewinderX
richmix wrote:Does the HTML source look like that, or the final outputted and processed page?
The outputted and processed page looks like that
Jcart wrote:hrmm, try

Code: Select all

$date = file($nukeurl.'/modules/'.$vwar_modulename.'/extra/nextactions.php');
That seems to work, but when I do print_r($date) it outputs
Array ( [0] => [1] => [2] => [8] => [9] => [17] => [18] => [24] => [25] => [33] => [34] => [40] => [41] => [49] => [50] => [56] => [57] => [65] => [66] => [72] => [73] => [81] =>
[3] => [6] => sTs vs. -BH- [7] => 30-12-06 at 9:00 pm
[19] => [22] => sTs vs. HSK [23] => 6-1-07 at 9:00 pm
[35] => [38] => sTs vs. LoD [39] => 7-1-07 at 8:00 pm
[51] => [54] => sTs vs. LoD [55] => 13-1-07 at 9:00 pm
[67] => [70] => sTs vs. UNP [71] => 14-1-07 at 3:00 pm
)
I'm not sure where ALL the array elements are coming from, ill clean up my html maybe that will fix it

Thanks

Posted: Fri Dec 29, 2006 2:58 pm
by John Cartwright
file() turns every line into an array element, so yes clean up your output.