如何将php输出行保持在一行中

如何将php输出行保持在一行中,php,html,css,Php,Html,Css,我刚刚制作了一个电话号码到时区的转换器,它将结果显示为: 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'])) {

我刚刚制作了一个电话号码到时区的转换器,它将结果显示为:

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>');
        }
if(!empty($record['country\u name'])){
$this->display(“国家:”。$record['Country\u name');
}
如果(!empty($record['city'])){
$this->display(“预期区域:”。$record['city']);
}
//echo json_编码($date);
如果(!empty($record['zone_name'])){
$this->display('时区:。$record['zone\u name']);
$this->display(“日期:”.Date('Y-m-d'));
$this->display(“时间:”.date('H:i:sa'));
}

谢谢您的帮助。

您需要创建一个字符串变量,并将所有输出连接到该字符串,如下所示:-

$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
$result='';//创建一个空字符串
如果(!empty($record['country\u name'])和&!empty($record['city'])和&!empty($record['zone\u name'])){
$result='国家:。$record['Country\u name']。时区:时区:。$record['zone\u name']。日期:时间:日期('H:i:s a');
}
echo$result;//打印输出

试试这个:如果你想在变量中传递它

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(!((空($record['country\u name'])和空($record['city'])和空($record['zone\u name'])){
$var='国家:。$record['Country\u name'].预期地区:。$record['city'.时区:。$record['zone\u name'.日期:。日期('Y-m-d')。时间:。日期('H:i:s a');
}
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;
if(!((空($record['country\u name'])和空($record['city'])和空($record['zone\u name'])){
$this->display(“国家:”。$record['Country\u name']。预期地区:”。$record['city']。时区:。$record['zone\u name']。日期:。日期('Y-m-d')。时间:。日期('H:i:s a');
}
退还$this;

你也可以显示你正在使用的显示功能的代码吗?我想他正在使用Smarty你的帖子确实有帮助,但问题是@AK SonuYou可以为此使用