string to an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

string to an array

Post 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
richmix
Forum Commoner
Posts: 31
Joined: Fri Dec 22, 2006 5:21 am

Post by richmix »

Does the HTML source look like that, or the final outputted and processed page?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

hrmm, try

Code: Select all

$date = file($nukeurl.'/modules/'.$vwar_modulename.'/extra/nextactions.php');
richmix
Forum Commoner
Posts: 31
Joined: Fri Dec 22, 2006 5:21 am

Post 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?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

file() turns every line into an array element, so yes clean up your output.
Post Reply