problem with parsing a text file [solved]

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
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

problem with parsing a text file [solved]

Post by smudge »

ok, first post, so hang w/ me.

i have a text file i use for creating calendars formatted as so:

Code: Select all

event[id]
event2[id2],event3[id3]
...
eventn[idn]
--------------------
(0 based "start on" day, ie: 0 = sun)
--------------------
id=popup data for id
id2=popup data for id2
...
basically, each line before the first --- is a day, so 31 lines = 31 days
in between the ---'s is the day the month starts on
after the ---'s are lookup tables for the specific event.
if you roll over event in the calendar, a small tooltip will appear containing the data in id

so far, i have the php parser picking apart the popup section:

Code: Select all

<?php
$popups=array();
	#linebreak fix
	array_shift($popup_raw);
	#for each line, break into id and data
	for($i=0,$l=sizeof($popup_raw); $i<$l; $i++){
		$p=explode("=",$popup_raw[$i]);
		echo "Raw: {$popup_raw[$i]}<br>";
		$id=$p[0];
		echo "Data before check: {$p[1]}<br>";
		if(!$p[1] || $p[1]=""){
			$p[1]="Details have yet to be announced";
			echo "EMPTY AND CHANGED<br>";
		} else {
			echo "NOT EMPTY: {$p[1]}<br>";
		}
		echo "Data after check: {$p[1]}<br>";
		$data=$p[1];
		$popups[$id]=$data;
		echo "$id : $data<hr>";
	}
?>
all the echos are just for debugging

and the file has this popup section:

Code: Select all

J1=
J2=
J3=
J4=
BP=Blah blah blah
J5=Blah blah blah
GB=Blah blah blah
SC=Blah blah blah
it outputs for j1:

Code: Select all

Raw: J1=
Data Before Check: 
EMPTY AND CHANGED
Data After Check: Details have yet to be announced
J1 : Details have yet to be announced
which is good. that's what it should output, but for BP:

Code: Select all

Raw: BP= Blah blah blah
Data Before Check: Blah blah blah
NOT EMPTY: 
Data After Check: 
BP :
which is not good, because somehow it's erasing $p[1]

please help! this is driving me insane
Last edited by smudge on Tue May 22, 2007 2:52 pm, edited 1 time in total.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

Sorry, just realized that i have an assignment = instead of a conditional == in the if statement.
Post Reply