这就是我的查询看起来像Controller:
public function index(){
$this->load->library('lib_pagination');
$pg_config['sql'] = "SELECT * from SjohlLBzads_products JOIN SjohlLBzads_products_meta ON SjohlLBzads_products.post_id = SjohlLBzads_products_meta.post_id ";
$pg_config['per_page'] = 50;
$data = $this->lib_pagination->create_pagination($pg_config);
$this->load->view("product_listing", $data);
}
这就是我在视图中显示它的方式(product_listing.php
)
<?php echo $data->gallery; ?>
问题是我从中得到的结果没有整理出来并包含网址和文字的混合:
a:6:{i:0;s:159:"https://ae01.alicdn.com/kf/HTB1AHOBOVXXXXazXpXXq6xXFXXXf/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:1;s:159:"https://ae01.alicdn.com/kf/HTB1ov9LOVXXXXbMXXXXq6xXFXXXl/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:2;s:159:"https://ae01.alicdn.com/kf/HTB1e4eHOVXXXXcbXXXXq6xXFXXXG/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:3;s:159:"https://ae01.alicdn.com/kf/HTB10qQ2RVXXXXbfXpXXq6xXFXXX5/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:4;s:159:"https://ae01.alicdn.com/kf/HTB164c0RVXXXXaSXpXXq6xXFXXXF/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:5;s:159:"https://ae01.alicdn.com/kf/HTB1OvumOVXXXXcqXFXXq6xXFXXXs/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";}
有什么方法可以提取这4个网址并单独调用/显示它们?
答案 0 :(得分:2)
希望这会对你有所帮助:
使用unserialize
解码$data->gallery
就像这样
$string = 'a:6:{i:0;s:159:"https://ae01.alicdn.com/kf/HTB1AHOBOVXXXXazXpXXq6xXFXXXf/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:1;s:159:"https://ae01.alicdn.com/kf/HTB1ov9LOVXXXXbMXXXXq6xXFXXXl/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:2;s:159:"https://ae01.alicdn.com/kf/HTB1e4eHOVXXXXcbXXXXq6xXFXXXG/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:3;s:159:"https://ae01.alicdn.com/kf/HTB10qQ2RVXXXXbfXpXXq6xXFXXX5/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:4;s:159:"https://ae01.alicdn.com/kf/HTB164c0RVXXXXaSXpXXq6xXFXXXF/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";i:5;s:159:"https://ae01.alicdn.com/kf/HTB1OvumOVXXXXcqXFXXq6xXFXXXs/COLROVIE-Work-Summer-Style-Women-Bodycon-Dresses-Sexy-2017-New-Arrival-Casual-Green-Crew-Neck-Half.jpg";}';
/*Replace $data->gallery with $string*/
$arr = unserialize($string);
print_r($arr);