dougong8012
2012-02-16 10:12
浏览 17
已采纳

如何在zendFramework中的数组上应用Zend_Filter_StripTags?

i want to apply Zend_Filter_StripTags on object array

$my_result = $obj->listdata(calling select query from model)

returned array is like

$my_result = 
 array  
      0 => 
         array
             'id' => string '1' (length=1)
             'value' => string '<script>' (length=10)
      1 => 
         array
             'id' => string '2' (length=1)
             'value' => string '<div>value</div>' (length=15)

how do i apply Zend_Filter_StripTags to $my_result

and i am passing this array to smarty

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsutuyxe088689 2012-02-16 10:21
    已采纳
    $my_result = $obj->listdata(calling select query from model);
    $filter = new Zend_Filter_StripTags();
    $result = array_map(array($filter, 'filter'), $my_result);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duanhong8839 2012-02-16 10:15

    Try with:

    $allowed_tags = array('img', 'a', 'strong', 'span');
    $allowed_attributes = array('alt', 'href', 'width', 'height');
    
    $filter = new Zend_Filter_StripTags($allowed_tags, $allowed_attributes);
    $output = array_map(array($filter, 'filter'), $my_result);
    

    Not tested because of no env.

    Edit:

    After you pasted a var dump try this:

    $allowed_tags = array('img', 'a', 'strong', 'span');
    $allowed_attributes = array('alt', 'href', 'width', 'height');
    
    $filter = new Zend_Filter_StripTags($allowed_tags, $allowed_attributes);
    $output = array();
    foreach ( $my_result as $data ) {
        $data['value'] = $filter->filter($data['value']);
        $output[] = $data;
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题