vulgarbulgar
vulgarbulgar

Reputation: 844

php output formatting

i have this:

<?php 
$values = $cfs->get('promoter'); 
if (!empty($values)) {
    echo $cfs->get_labels('promoter');  
    echo implode(', ', array_keys($values));
}
?>
<br />

which prints something like this:

PromoterPromoter1, Promoter2

when i'd like something like this:

Promoter: Promoter1, Promoter2

also, how could i include the <br />within the php, so if the field is blank, the line break is also excluded?

thanks.

Upvotes: 0

Views: 118

Answers (3)

raven
raven

Reputation: 123

<?php 
$values = $cfs->get('promoter'); 
if (!empty($values)) {
    $word = "";
    $word .= $cfs->get_labels('promoter');
    $word .= ": ";
    $word .= implode(', ', array_keys($values));
    $word .= "<br />";
    echo $word;
}
?>

Upvotes: 0

Lews Therin
Lews Therin

Reputation: 10995

<?php 
$values = $cfs->get('promoter'); 
if (!empty($values)) {
    echo $cfs->get_labels('promoter').": ";  
    echo implode(', ', array_keys($values))."<br />";
}
?>

Use PHP's concatenation operator - i.e. a period.

Upvotes: 2

Ibu
Ibu

Reputation: 43810

You can simply append a string ": " to the end

echo $cfs->get_labels('promoter').": ";  

Upvotes: 1

Related Questions