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

标签 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'])) {
            $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_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;

关于php - 如何将 php 输出行保持在一行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31824604/

相关文章:

javascript - ReactJS输入类型="number"仅响应旋转按钮,不响应手动输入

javascript - 访问 NgClass 内的 HTML 元素值

javascript - 为什么 Facebook 导航栏固定并放置在顶部不会在移动到其他页面时重新加载?

php - 如何每天自动调用一个php脚本自动发送邮件

php - Wordpress 无法通过 ajax 请求加载正确的语言 mo 文件

javascript - 使用 Javascript 在 &lt;header&gt; 标签上方编写代码

html - 如何让我所有的 radio /复选框都对齐?

javascript - 切换 CSS3 淡入淡出?

php - 多个 ResultSet 到变量 PHP

php - 如何从管理员端注销php中的所有事件登录用户