在PHP函数输出之间插入冒号

时间:2015-11-09 09:24:49

标签: php user-defined-functions

我有以下PHP函数:

protected function getFieldRow($label, $value, $encode = true)
{
    if (empty($value))
    {
        return '';
    }

    return FoxHtmlElem::create()->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean($label)))->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))->render();
}

哪个输出到以下列表:

<dt class="field-title">Label</dt><dd class="field-content">Value</dd>
<dt class="field-title">Label</dt><dd class="field-content">Value</dd>
<dt class="field-title">Label</dt><dd class="field-content">Value</dd>

如何更改函数以在输出中以纯文本形式添加冒号“”,如下所示:

<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>
<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>
<dt class="field-title">Label : </dt><dd class="field-content">Value</dd>

2 个答案:

答案 0 :(得分:2)

为什么不将它与标签一起添加,如:

<dt class="field-title">Label :</dt>

你可以通过连接&#39;来实现这一点:&#39;带标签;

$label .= " : ";

希望这有帮助!

答案 1 :(得分:1)

如果你在那里放置一个冒号,它会出现但不在描述清单的规则和样式之内。

我假设你会在标签标签中想要它,如:

protected function getFieldRow($label, $value, $encode = true)
{
    if (empty($value))
    {
        return '';
    }

    return FoxHtmlElem::create()
        ->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean("{$label}:")))
        ->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))
        ->render();
}

如果你确实想要它的最初方式,我猜这是解决方案(虽然谷歌不知道你正在使用什么类,所以我也不能测试它)

protected function getFieldRow($label, $value, $encode = true)
{
    if (empty($value))
    {
        return '';
    }

    return FoxHtmlElem::create()
        ->append(FoxHtmlElem::create('dt')->classes('field-title')->text(JFilterInput::getInstance()->clean($label)))
        ->append(":")
        ->append(FoxHtmlElem::create('dd')->classes('field-content')->html($encode ? nl2br(FoxHtmlEncoder::encode(JFilterInput::getInstance()->clean($value))) : $value))
        ->render();
}