在 PHP 函数输出之间插入冒号
Inserting Colon Between PHP Function Output
我有以下 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>
为什么不将它添加到标签旁边,例如:
<dt class="field-title">Label :</dt>
您可以将“:”与标签连接起来;
$label .= " : ";
希望对您有所帮助!
如果您在此处放置一个冒号,它会出现但超出描述列表的规则和样式。
我假设您会像这样在 label 标签中使用它:
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();
}
如果您确实希望按照最初的要求使用它,我猜这就是解决方案(尽管 google 不知道 类 您正在使用什么,所以也不知道我所以我无法测试它)
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();
}
我有以下 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>
为什么不将它添加到标签旁边,例如:
<dt class="field-title">Label :</dt>
您可以将“:”与标签连接起来;
$label .= " : ";
希望对您有所帮助!
如果您在此处放置一个冒号,它会出现但超出描述列表的规则和样式。
我假设您会像这样在 label 标签中使用它:
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();
}
如果您确实希望按照最初的要求使用它,我猜这就是解决方案(尽管 google 不知道 类 您正在使用什么,所以也不知道我所以我无法测试它)
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();
}