colFormat=false; $this->colStyle=false; $this->colField=array(); $i1=strpos($template,"{"); while ($i1>0 || $i1===0) { $i2=strpos($template,"}",$i1+1); $field=substr($template,$i1+1,$i2-$i1-1); $j1=strpos($field,"%"); if ($j1!==false) { $j2=strpos($field,"%",$j1+1); $format=substr($field,$j1+1,$j2-$j1-1); $field=substr($field,$j2+1); $this->colFormat[$field]=$format; } $j1=strpos($field,"@"); if ($j1!==false) { $j2=strpos($field,"@",$j1+1); $style=substr($field,$j1+1,$j2-$j1-1); $field=substr($field,$j2+1); $this->colStyle[$field]=$style; } $this->colField[]=$field; $i1=strpos($template,"{",$i2); } if ($this->colFormat) { foreach($this->colFormat as $key => $value) {$template=preg_replace("/%$value%$key/i",$key,$template);} } if ($this->colStyle) { foreach($this->colStyle as $key => $value) {$template=preg_replace("/@$value@$key/i",$key,$template);} } $this->template=$template; } function parse($data) { if (strlen($this->template)==0) return false; $template=$this->template; foreach($this->colField as $field) { if (is_array($data)) {$value=isset($data[$field]) ? $data[$field] : "";} else {$value=isset($data->$field) ? $data->$field: "";} if ($this->colFormat && isset($this->colFormat[$field])) {$value=$this->colFormat[$field]($value);} if ($this->colStyle && isset($this->colStyle[$field])) {$value=$this->colStyle[$field]($value,$field);} //$value=nl2br($value); $template=preg_replace("/\{$field\}/i",$value,$template); } return $template; } } ?>