Page 1 of 1

Help with something that should be basic to me... Exploding

Posted: Mon Feb 10, 2003 1:58 pm
by Sky
I don't quite get it... I want to syndicate news on my site. Here's a example item...

Code: Select all

Date	Contest	Comment
2003-2-3 6:29 pm	Hallway Hunt	callmeminyme enters FearMK1, 
a UFO with a combination MG and Rocket attack.
FearMK1 ranks in at 3rd, hot on the heels of Assassin Major Mk2...

2003-2-1 3:54 pm	Arena Combat	Liebig enters Attila junior which ranks in at 25th. 
BattleSkins2 updated with Attila junior's skin.

2003-2-1 3:38 pm	Maze	Burnin Pancake enters MazorEyeICE. 
Like MazeMonkey, MazorEyeICE uses a combination of MazorBlade's left-right search 
and MazeMonkey's dead end elimination.
The combination should make it the top, but it still needs a bit of tweaking and 
unfortunately it also has a bug that crops 
up in Maze 1, so it doesn't ever finish that maze, giving it an overall score of 141 
which ties for 2nd with Frantic (which is still great performance!)
I want it at least split up by date groups, but if possible by date[contest],[message]

here's my confuzzled code::

Code: Select all

<? 
global $item1;
function file_to_array($item1, $itemurl, $seperator)
{
	#$item['content1'] = @require($item_url);
	
	//Add delimiters
	$item1['content1'] = str_replace("2003", "|2003", $item1['conent1']);
	$item1['content1'] .= $seperator;
//#if(($explode == true) and ($item['url'] != '') and (@require($item['url']) != ''))
		$item1['array'] = explode($seperator, $item1['content1']);
}

$item1['content1'] = "2003-2-3 6:29 pm	Hallway Hunt	callmeminyme enters FearMK1, ";
$item1['content1'] .= "a UFO with a combination MG and Rocket attack.";
$item1['content1'] .= "FearMK1 ranks in at 3rd, hot on the heels of Assassin Major Mk2...";
$item1['content1'] .= "";
$item1['content1'] .= "2003-2-1 3:54 pm	Arena Combat	Liebig enters Attila junior which ranks in at 25th. ";
$item1['content1'] .= "BattleSkins2 updated with Attila junior's skin.";
$item1['content1'] .= "";
$item1['content1'] .= "2003-2-1 3:38 pm	Maze	Burnin Pancake enters MazorEyeICE. ";
$item1['content1'] .= "Like MazeMonkey, MazorEyeICE uses a combination of MazorBlade's left-right search ";
$item1['content1'] .= "and MazeMonkey's dead end elimination.";
$item1['content1'] .= "The combination should make it the top, but it still needs a bit of tweaking and ";
$item1['content1'] .= "unfortunately it also has a bug that crops ";
$item1['content1'] .= "up in Maze 1, so it doesn't ever finish that maze, giving it an overall score of 141 ";
$item1['content1'] .= "which ties for 2nd with Frantic (which is still great performance!)";
 file_to_array($item1, "", "|");
 print_r($item1['array']);
 ?>
Please note that the above was created with getting the file in mind and changed for debugging ease... to me at least :P

Posted: Mon Feb 10, 2003 2:07 pm
by patrikG
The only thing I see wrong in your code is

Code: Select all

$item1&#1111;'content1'] = str_replace("2003", "|2003", $item1&#1111;'conent1']);
you forgot a "t" in $item1['conent1'] :)

Apart from that my tired eyes don't see a thing :p

Posted: Mon Feb 10, 2003 2:54 pm
by Sky
-Thanks.... I'll try that...

Well.. it's still returning blank. And my coding-bored eyes can't see anything else...

Re: Help with something that should be basic to me... Explod

Posted: Mon Feb 10, 2003 5:39 pm
by gyardleydn
Either

1. Move the global declaration. It needs to be declared global in each and every function that you want to access it instead of a local version
[Listing]

2. Get rid of the global variable and use return to copy the array back to the global context after manipulating a local copy

Code: Select all

<?php 

function file_to_array($itemurl, $seperator) 
{ 
   #$item['content1'] = @require($item_url); 
    
   //Add delimiters 
   global $item1; 
   $item1['content1'] = str_replace("2003", "|2003", $item1['content1']); 
   $item1['content1'] .= $seperator; 
//#if(($explode == true) and ($item['url'] != '') and (@require($item['url']) != '')) 
      $item1['array'] = explode($seperator, $item1['content1']); 
} 

$item1['content1'] = "2003-2-3 6:29 pm   Hallway Hunt   callmeminyme enters FearMK1, "; 
$item1['content1'] .= "a UFO with a combination MG and Rocket attack."; 
$item1['content1'] .= "FearMK1 ranks in at 3rd, hot on the heels of Assassin Major Mk2..."; 
$item1['content1'] .= ""; 
$item1['content1'] .= "2003-2-1 3:54 pm   Arena Combat   Liebig enters Attila junior which ranks in at 25th. "; 
$item1['content1'] .= "BattleSkins2 updated with Attila junior's skin."; 
$item1['content1'] .= ""; 
$item1['content1'] .= "2003-2-1 3:38 pm   Maze   Burnin Pancake enters MazorEyeICE. "; 
$item1['content1'] .= "Like MazeMonkey, MazorEyeICE uses a combination of MazorBlade's left-right search "; 
$item1['content1'] .= "and MazeMonkey's dead end elimination."; 
$item1['content1'] .= "The combination should make it the top, but it still needs a bit of tweaking and "; 
$item1['content1'] .= "unfortunately it also has a bug that crops "; 
$item1['content1'] .= "up in Maze 1, so it doesn't ever finish that maze, giving it an overall score of 141 "; 
$item1['content1'] .= "which ties for 2nd with Frantic (which is still great performance!)"; 
file_to_array("", "|"); 
print_r($item1['array']); ?>

Posted: Thu Feb 13, 2003 9:37 am
by Sky
ok.... it sortof works now. (added global in and out of function, returned item1) But i end up with a blank array key at the start and end. ::


Array
(
[0] =>
[1] => 2003-2-3 6:29 pm Hallway Hunt callmeminyme enters FearMK1, a UFO with a combination MG and Rocket attack.FearMK1 ranks in at 3rd, hot on the heels of Assassin Major Mk2...
[2] => 2003-2-1 3:54 pm Arena Combat Liebig enters Attila junior which ranks in at 25th. BattleSkins2 updated with Attila junior's skin.
[3] => 2003-2-1 3:38 pm Maze Burnin Pancake enters MazorEyeICE. Like MazeMonkey, MazorEyeICE uses a combination of MazorBlade's left-right search and MazeMonkey's dead end elimination.The combination should make it the top, but it still needs a bit of tweaking and unfortunately it also has a bug that crops up in Maze 1, so it doesn't ever finish that maze, giving it an overall score of 141 which ties for 2nd with Frantic (which is still great performance!)
[4] =>
)

I'm experimenting, but i need thoes empty keys out of there and I need to seperate each item by date, contest, and content.

Posted: Thu Feb 13, 2003 10:18 am
by Sky
Ok, i got it working. I sliced out the arrays and exploded with " "

Re: Help with something that should be basic to me... Explod

Posted: Thu Feb 13, 2003 10:31 am
by gyardleydn
Either

1. Move the global declaration. It needs to be declared global in each and every function that you want to access it instead of a local version
[Listing]

2. Get rid of the global variable and use return to copy the array back to the global context after manipulating a local copy

All the variables that you declare outside of any function are already global. So you need only declare something global inside a function. If in your actual code you fill your array in a function then you would have to declare it global there as well. Is that what you mean by "added global in and out of function?"

Either, as in one or the other. If you use global you do not need to return the array or give it to the function as a parameter since both already have access to that variable. (see my code previous example)

Since the the content1 element starts with "2003", it becomes "|2003..."

Oh, nevermind, glad to see you got it working.