class Forum_model extends CI_Model {
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
parent::__construct();
$this->load->database();
$this->load->helper(array('url'));
}
function badfilter($text)
{
$filter_terms = array('\bass(es|holes?)?\b', '\bshit(e|ted|ting|ty|head)\b','\bf[ ]*u[ ]*c[ ]*k[]*\b','\bf+u+c+k+\b');
$filtered_text = $text;
foreach($filter_terms as $word)
{
$match_count = preg_match_all('/' . $word . '/i', $text, $matches);
for($i = 0; $i < $match_count; $i++)
{
$bwstr = trim($matches[0][$i]);
$filtered_text = preg_replace('/\b' . $bwstr . '\b/', str_repeat("*", strlen($bwstr)), $filtered_text);
}
}
return $filtered_text;
}
/**
* create_forum function.
*
* @access public
* @param string $title
* @param string $description
* @return bool
*/
public function create_forum($title, $description) {
$data = array(
'title' => $title,
'slug' => strtolower(url_title($title)),
'description' => $description,
'created_at' => date('Y-m-j H:i:s'),
);
return $this->db->insert('forums', $data);
}
/**
* get_forum_id_from_forum_slug function.
*
* @access public
* @param string $slug
* @return int
*/
public function get_forum_id_from_forum_slug($slug) {
$this->db->select('id');
$this->db->from('forums');
$this->db->where('slug', $slug);
return $this->db->get()->row('id');
}
/**
* get_topic_id_from_topic_slug function.
*
* @access public
* @param string $topic_slug
* @return int
*/
public function get_topic_id_from_topic_slug($topic_slug) {
$this->db->select('id');
$this->db->from('topics');
$this->db->where('slug', $topic_slug);
return $this->db->get()->row('id');
}
/**
* get_forums function.
*
* @access public
* @return array of objects
*/
public function get_forums() {
$text=$this->db->get('forums')->result();
$this->badfilter($text);
}
}
上面的代码是项目文件的控制器,经过一些修正后仍然显示数组到字符串的转换错误。 请看上面的代码