(新手求大神)自定义标签 解析问题

浏览:533 发布日期:2015/01/05 分类:求助交流 关键字: 标签 解析
自定义标签库代码:<?php
    class TagLibStl extends TagLib{
        protected $tags = array(
                'contents'=>array('attr'=>'channel_index','close'=>1),
        'content'=>array('attr'=>'type','close'=>1)
     );
public function _content($attr,$content){
  $tag= $this->parseXmlAttr($attr,'content');
  $type= $tag['type'];
  $parseStr="[filed:".$type."]";
  return $parseStr;
}
public function _contents($attr,$content){
  $tag        = $this->parseXmlAttr($attr,'contents');
  $channelIndex=$tag['channel_index'];
  $cate=M('content');
  $tb=$cate->select();
  for($i=0; $i<count($tb);$i++){
    $c=str_replace(array("[filed:title]","[filed:keywords]"),array($tb[$i]['Title'],$tb[$i]['Keywords']),$content);
    $str.=$c;
  }
    return $str;
 }
模板代码<taglib name='Stl' />
<stl:contents channel_index="专题">
  <stl:content type="title"></stl:content>
  <stl:content type="keywords"></stl:content>
</stl:contents>
问题1、
tp能不能做到从内到外的解析,就是我先解析非闭合标签里面的stl:content的内容,再解析stl:contents,如果可以请问大神怎么实现这过程。

问题2、
如果问题一不能解决,见上述代码,stl:content和stl:contents这两个非闭合标签而且内容有联系 那我应该怎么解析?请大神提供一下思路,谢谢!~
最佳答案
评论( 相关
后面还有条评论,点击查看>>