2012-02-16 56 views
4

我想對象數組上應用Zend_Filter_StripTags如何在ZendFramework的數組上應用Zend_Filter_StripTags?

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

返回數組類似於

$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) 

我該如何申請Zend_Filter_StripTags$my_result

和我傳遞這個數組給Smarty

回答

0
$my_result = $obj->listdata(calling select query from model); 
$filter = new Zend_Filter_StripTags(); 
$result = array_map(array($filter, 'filter'), $my_result); 
+0

不工作..先生 – 2012-02-16 10:43:36

0

試穿:

$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); 

未測試,因爲沒有env。

編輯:

您粘貼後一個變種轉儲試試這個:

$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; 
} 
+0

想法在一個方向:) – SMka 2012-02-16 10:23:44

+0

不工作..先生 – 2012-02-16 10:43:15

+0

看看我的編輯。 – hsz 2012-02-16 11:12:28

相關問題