NYCPHP Meetup

NYPHP.org

[nycphp-talk] Disappearing data or I've gone mad

Jeremy Hise jhise at nextsource.com
Wed Feb 12 14:11:42 EST 2003


I know it's not the this->data....

But, data is being passed to the object and created as:
	[calling page]
	$data[first_name] = "Jeremy";
	$data[last_name] = "Hise";
	...
	$tmpl = new template("user_profile", $data);
	...
	[in constructor]
	$this->data = $data;
	...
	function parse() {
	...

get_tags() basically opens the template file, and, using a regex, compiles an array of keywords found between <smac> and </smac>. That array is then returned to parse().

In that function I had:

while(list($key,$value) = each($this->data)) {
	print($key . " = " . $value . "<br>");
}

Above the is_array() check

And I got what I expected:

first_name = Jeremy
last_name = Hise
email = jhise at nextsource.com

etc...

I've tried with quotes, without quotes, if tried a for($i = 0; $i < sizeof($kws); $i++), I've tried every single possible thing that I can think of...

In the meanwhile I've reversed the method and the loop is based on the this->data...but my templates will eventually need to have value-less keys (like "CURRENT_DATE" which will evaluate to the current time).

It's driv'n me nuts

The regex, btw, is "/<smac>([^<>]*)<\\/smac>/i" used with preg_match_all().

Thanks for everyone's input.

On Wed, 12 Feb 2003 13:47:00 -0500
"Jon Baer" <jonbaer at jonbaer.net> wrote:

> I don't get where you declare data[] array to begin with.  Can you post more
> code?  Id try it without the "quotes" since you don't need to interpret any
> string w/ it.
> 
> - Jon
> 
> ----- Original Message -----
> From: "Jeremy Hise" <jhise at nextsource.com>
> To: "NYPHP Talk" <talk at nyphp.org>
> Sent: Wednesday, February 12, 2003 12:58 PM
> Subject: [nycphp-talk] Disappearing data or I've gone mad
> 
> 
> > Hi:
> >
> > I have a very strange situation that may be difficult for me to
> convey...but either PHP is having problems, or I'm just a jackass.
> >
> > Here is the weirdo code with some of my attempt to debug. $this->data
> contains an array of "keys" that need to be replaced with values. This is
> kind of a ghetto template parser. Everything is fine until I get inside the
> for loop (which used to be a foreach...but I'm trying everything. Inside
> that loop, I cannot get $this->data[$key] to print out anything!
> >
> > I'm just basically looking for someone to see if I'm overlooking
> something.
> >
> > Thanks a billion!
> >
> > hise
> >
> >      function parse() {
> >         // Get an array of items such as 'first_name', 'last_name', etc
> >         $kws = $this->get_tags();
> >
> >         // If we do have an array of keywords
> >         if(is_array($kws)) {
> >             // For each keyword
> >             foreach($kws as $kw) {
> >                 // Get the value from this object's data hasa
> >                 $value = $this->data["$kw"];  // <-- this has no data in
> it inside this loop
> >                 // Replace the smac tagged keyword with the value
> >                 $this->body = ereg_replace("<smac>".$kw."</smac>", $value,
> $this->body);
> >             }
> >         }
> >         return($this->body);
> >     }
> >
> >
> >
> > --
> >
> > -+----------------------+
> >  | jhise at nextsource.com |
> >  | developer            |
> >  | nextSource, Inc.     |
> >  | x334                 |
> >  +----------------------+
> >
> >
> > 
> >
> >
> >
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 


-- 

-+----------------------+
 | jhise at nextsource.com |
 | developer            |
 | nextSource, Inc.     |
 | x334                 |
 +----------------------+



More information about the talk mailing list