删除Codeigniter查询中不需要的字符

时间:2018-05-09 13:31:14

标签: codeigniter url

我有一个产品数据库,我希望在我的CI网站上显示,但它有一个产品标题/名称表。

productUrl table 中的产品网址包含产品名称:

https://www.websitename.com/item/Dream-Feather-Autumn-Winter-Fleece-Oh-Yes-Letter-Harajuku-Print-Pullover-Thick-Loose-Women-Hoodies-Sweatshirt/32810266388.html

如何删除' https://www.websitename.com/item/', - 末尾的 - 符号和html扩展程序' 32810266388.html'所以我只能显示

"梦幻羽毛秋冬季 - 羊毛哦是字母原宿印花套衫厚实宽松女装连帽衫运动衫"

控制器:

public function custom()
{

    $this->load->database();
    $this->load->model('Users');


    $params = array();
    $total_records = $this->Users->get_total();

型号:

public function get_current_page_records($limit, $start) 
{
    $this->db->limit($limit, $start);
    $this->db->select("*");
        $this->db->from("SjohlLBzads_products");
        $this->db->join('SjohlLBzads_products_meta', 'SjohlLBzads_products_meta.post_id = SjohlLBzads_products.post_id');
        $this->db->join('SjohlLBzads_ali_meta', 'SjohlLBzads_ali_meta.post_id = SjohlLBzads_products.post_id');
        $query = $this->db->get();

    if ($query->num_rows() > 0) 
    {
        foreach ($query->result() as $row) 
        {
            $data[] = $row;
        }

        return $data;
    }

    return false;
}

查看:

<?php echo $data->productUrl ?>

1 个答案:

答案 0 :(得分:0)

假设:

$config['base_url'] = "https://websitename.com"; // application/config/config.php

使用URI细分:

echo $this->uri->segment(1);  // item
echo $this->uri->segment(2);  // Dream Feather Autumn Winter-Fleece Oh Yes Letter Harajuku Print Pullover Thick Loose Women Hoodies Sweatshirt
echo $this->uri->segment(3); // 32810266388.html OR 32810266388 (depends how .html got there)

所以,在这个非常具体的案例中:

echo $this->uri->segment(2);
or
$var = $this->uri->segment(2);

我对你的控制器/模型/视图代码感到很困惑,因为它们似乎与问题无关。如果上面没有回答你的问题,请编辑它并添加更多细节,我会相应更新我的。