如何将 html_entity_decode 添加到数组?
我正在 codeigniter 中使用 TinyMCE 制作内容条目。 但是输出源如下所示,并且不显示 <和>。相反,它显示 HTML 实体,例如 &lessthan;和&大于;等等。
该条目是由管理员登录后输入的。
输出来自数据库。
我在模型中取出了 escape,但它仍然做同样的事情。
我还有一个配置设置 $config['global_xss_filtering'] = FALSE;
所以我想添加html_entity_decode。但 $page_data 是一个数组。 该数组包含 id、标题、内容和用于页面项目的 slug。
谁能告诉我该怎么做吗?
输出示例:
<p><img src="images/icon1.png" border="0"
alt="icon" width="48" height="48" />
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
型号代码:
<?php
class Pagemodel extends Model
{
....
...
/**
* Return an array of a page — used in the front end
*
* @access public
* @param string
* @return array
*/
function fetch($slug)
{
$query = $this->db->query("SELECT * FROM `pages` WHERE `slug` = '$slug'");
return $query->result_array();
}
...
...
}
?>
控制器代码:
function index()
{
$page_slug = $this->uri->segment('2'); // Grab the URI segment
if($page_slug === FALSE)
{
$page_slug = 'home';
}
$page_data = $this->pages->fetch($page_slug); // Pull the page data from the database
if($page_data === FALSE)
{
show_404(); // Show a 404 if no page exists
}
else
{
$this->_view('index', $page_data[0]);
}
}
I am making a content entry with TinyMCE in codeigniter.
However the output source is like the following and does not show < and >. Instead it shows HTML enties like &lessthan; and &greaterthan; etc.
The entry is made by admin after logged in.
Output comes from database.
I took out escape in model, but it still does the same thing.
Also I have a config setting, $config['global_xss_filtering'] = FALSE;
So I want to add html_entity_decode. But the $page_data is an array.
The array has id, title, content and slug which is used for page item.
Could anyone tell me how to do it please?
Output example:
<p><img src="images/icon1.png" border="0"
alt="icon" width="48" height="48" />
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Model code:
<?php
class Pagemodel extends Model
{
....
...
/**
* Return an array of a page — used in the front end
*
* @access public
* @param string
* @return array
*/
function fetch($slug)
{
$query = $this->db->query("SELECT * FROM `pages` WHERE `slug` = '$slug'");
return $query->result_array();
}
...
...
}
?>
Controller code:
function index()
{
$page_slug = $this->uri->segment('2'); // Grab the URI segment
if($page_slug === FALSE)
{
$page_slug = 'home';
}
$page_data = $this->pages->fetch($page_slug); // Pull the page data from the database
if($page_data === FALSE)
{
show_404(); // Show a 404 if no page exists
}
else
{
$this->_view('index', $page_data[0]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我没猜错的话,你想传递“html_entity_decode”。从数据库返回的所有字段。您可以轻松地向您的获取函数添加一些内容:
如果我正确地回答了您的问题,那么应该可以满足您的要求。
If I got you correctly you want to pass 'html_entity_decode.' to all fields that are returned from your database. You can easily add something to your fetch function:
If I got your question right that should do what you want.
如果您希望避免在结果集上循环,您可以使用 的功能
并执行如下操作:
If you prefer avoid cycling on the resultset, you can use the facilities of
and do something like this: