首页 > 解决方案 > php中的字符串内容

问题描述

我想用条件连接多个字符串

我在 ajax 和 php 中做一个加载,我想动态响应,所以我尝试了下面的代码

$newList .= '<ul>';
$newList .= '<li>';
$newList .= '<i class="fa fa-calendar"></i>';
$newList .= $this->Common_model->startend_date_format($getEvent['event_stat'], $getEvent['event_end']);
$newList .= '</li>';
$newList .= '<li>';
$newList .= '<i class="fa fa-map-marked"></i>';
if ($city != "") {
    $newList .= '<a href=' . base_url() . 'city/' . $this->Common_model->makeSeoUrl($city) . '>' . ucfirst($city) . '</a>, &nbsp;' ;
}                    
if ($state != "") {
    $newList .= '<a href="' . base_url() . 'state/' . $this->Common_model->makeSeoUrl($state) . '>' . ucfirst($state) . '</a>, &nbsp';
}
if ($get_country_name != "") {
    $newList .= '<a href=' . base_url() . 'country/' . $this->Common_model->makeSeoUrl($get_country_name) . '/' . base64_encode($get_country_id) . '>' . ucfirst($get_country_name) . '</a>';
}
$newList .= '</li>';
$newList .= '<li>';
$newList .= '<i class="fa fa-tags"></i>';
$newList .= '<a href=' . base_url() . 'categories' . '#' . $cat_name_event . '>' . $cat_name_event . '</a>';
$newList .= '</li>';
$newList .= '</ul>';

它显示了类似的东西

尝试连接

但实际结果应该是这样的

实际连接

标签: phpconcatenationstring-concatenation

解决方案


推荐阅读