How to save php output lines in one line

I just made a phone number for the timezone converter, and it displays the result as:

Requested Phone No.: +1 732 78782722 Country: United States 

Expected Region: Newark, New Brunswick

 Timezone: America/New_York Date: 2015-08-05 Time: 01:51:03 am 

I want to do all these outputs in one line. Here is my output code

  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('Ym-d') . '</h2>'); $this->display('<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>'); } 

Thanks for the help.

+5
source share
2 answers

Try: If you want to pass this in a variable

 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('Ym-d') . '</h2>' . '<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>'; } echo $var; 

Or this if you want to pass your object:

 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('Ym-d') . '</h2>' . '<h2><strong>Time:</strong> ' . date('H:i:s a') . '</h2>'); } return $this; 
+7
source

You need to create a string variable and combine all your output into this string, as shown below: -

 $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('Ym-d') . '</h2>'.' <h2><strong>Time:</strong> '. date('H:i:s a') . '</h2>'; } echo $result; // print output 
+2
source

All Articles