我刚给时区转换器拨了一个电话号码,结果显示为:
Requested Phone No.: +1 732 78782722
Country: United States
预期地区:纽瓦克,新不伦瑞克省
Timezone: America/New_York
Date: 2015-08-05
Time: 01:51:03 am
我想要做的是将所有这些输出放在一行中。 这是我的输出代码
if(!empty($record['country_name'])) {
$this->display('<strong>Country:</strong> ' . $record['country_name']);
}
if(!empty($record['city'])) {
$this->display('<strong>Expected Region:</strong> ' . $record['city']);
}
//echo json_encode($date);
if(!empty($record['zone_name'])) {
$this->display('<strong>Timezone:</strong> ' . $record['zone_name']);
$this->display('<h2><strong>Date:</strong> ' . date('Y-m-d') . '</h2>');
$this->display('<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>');
}
感谢您的帮助。
答案 0 :(得分:7)
试试这个:如果你想在变量中传递它
if(!((empty($record['country_name']) && empty($record['city']) && empty($record['zone_name'])) {
$var = '<strong>Country:</strong> ' . $record['country_name'] . '<strong>Expected Region:</strong> ' . $record['city'] . '<strong>Timezone:</strong> ' . $record['zone_name']. '<h2><strong>Date:</strong> ' . date('Y-m-d') . '</h2>' . '<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>';
}
echo $var;
或者,如果你想传递你的对象:
if(!((empty($record['country_name']) && empty($record['city']) && empty($record['zone_name'])) {
$this->display('<strong>Country:</strong> ' . $record['country_name'] . '<strong>Expected Region:</strong> ' . $record['city'] . '<strong>Timezone:</strong> ' . $record['zone_name']. '<h2><strong>Date:</strong> ' . date('Y-m-d') . '</h2>' . '<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>');
}
return $this;
答案 1 :(得分:2)
您需要创建一个字符串变量并将所有输出连接到该字符串,如下所示: -
$result = ''; // create an empty string
if(!empty($record['country_name']) && !empty($record['city']) && !empty($record['zone_name'])){
$result = '<strong>Country:</strong> ' . $record['country_name'].' <strong>Timezone:</strong> '. $record['city'].' <strong>Timezone:</strong> '.$record['zone_name'].' <h2><strong>Date:</strong> '. date('Y-m-d') . '</h2>'.' <h2><strong>Time:</strong> '. date('H:i:s a') . '</h2>';
}
echo $result; // print output