有人可以看一下吗?
我想在echo htmlspecialchars($title)
中展示<h2>
,但我尝试的所有内容都会显示空白页。
<div class="adsmanager_ads_desc">
<?php $strtitle = "";
if (@$this->positions[5]->title) {
$strtitle = JText::_($this->positions[5]->title);
}
echo "<h2>" . @$strtitle . "</h2>";
if (isset($this->fDisplay[6]))
{
foreach($this->fDisplay[6] as $field) {
$c = $this->field->showFieldValue($this->content,$field);
if ($c != "") {
$title = $this->field->showFieldTitle(@$this->content->catid,$field);
if ($title != "") {
echo htmlspecialchars($title).": ";
echo "$c<br/>";
}
}
}
}
?>
</div>
有什么建议吗?
答案 0 :(得分:0)
尝试以下操作,如果它抛出错误,请说明它们是什么
<div class="adsmanager_ads_desc">
<?php
$strtitle = (is_string($this->positions[5]->title)) ? $this->positions[5]->title : '';
echo "<h2>" . $strtitle . "</h2>";
if (isset($this->fDisplay[6]) && is_array($this->fDisplay[6]))
{
foreach($this->fDisplay[6] as $field) {
$field_value = $this->field->showFieldValue($this->content, $field);
if (is_string($field_value) && strlen($field_value) > 0) {
$title = $this->field->showFieldTitle($this->content->catid,$field);
if (is_string($title) && strlen($title) > 0) {
echo htmlspecialchars($title).": " . $field_value . "<br/>";
}
}
}
}
?>
</div>
我还添加了一些is_string等,这不是必要的,但可以帮助debuging(虽然如果它是一个int | double它应该通过
答案 1 :(得分:0)
你正在压制错误并想知道出了什么问题。在开发过程中,错误报告是您的朋友。
而不是这个
if (@$this->positions[5]->title) {
$strtitle = JText::_($this->positions[5]->title);
}
试试这个
$strtitle = JText::_($this->positions[5]->title) || "Error bro";
答案 2 :(得分:0)
你的意思是
<h2><?php echo htmlspecialchars($title).": "; ?></h2>
你也可以试试吗
<div class="adsmanager_ads_desc">
<?php $strtitle = "";
if (@$this->positions[5]->title) {
$strtitle = JText::_($this->positions[5]->title);
}
echo "<h2>" . @$strtitle . "</h2>";
if (isset($this->fDisplay[6]))
{
foreach($this->fDisplay[6] as $field) {
$c = $this->field->showFieldValue($this->content,$field);
if ($c != "") {
$title = $this->field->showFieldTitle(@$this->content->catid,$field);
if ($title != "") {
echo '<h2>'.htmlspecialchars($title).':'.'</h2>';
echo "$c<br/>";
}
}
}
}
?>
</div>