2015-09-30 58 views
0

我在哪裏可以使用PHP str_replace函數將'¶'轉換爲< br>或\ n?PHP函數str_replace應該放在MVC的哪裏?

我試着看着有關how to use str_replacehow to convert ¶ to \n in PHP的帖子。我也嘗試在模型中添加str_replace而不是在查詢中。

WinnerStatement

「Hello¶¶,我是贏家」

型號

public function early_results($user_id) { 
    $sql = " 
     SELECT 
      l.winnerStatement AS WinnerStatement, 
      l.recipient AS Recipient, 
     FROM Letter l 
     WHERE 
      l.winnerId = '{$this->db->escape($user_id)}';"; 
    return $this->db->query($sql)->result(); 
} 

查看

<td><?=$feed_item->WinnerStatement?></td> 

控制器

$this->load->view('dashboard/snippet/winners', array('WinnerStatement' => $winner_statement)); 
+2

請參閱[如何提問](http://stackoverflow.com/help/how-to-ask ) –

+1

'​​<?php echo str_replace('¶','
',$ feed_item-> WinnerStatement); ?>' – RamRaider

+0

可以在查詢'REPLACE(l.winnerStatement,'¶','
')AS ...' – Deadooshka

回答

4

您可以設置它在視圖

<td><?=str_replace('¶', '<br />', $feed_item->WinnerStatement)?></td>