0

有人可以看看这个。

我想显示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>

有什么建议么?

4

3 回答 3

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>
于 2013-05-24T08:46:59.403 回答
0

您正在压制错误并想知道哪里出了问题。在开发中,错误报告是你的朋友。

而不是这个

if (@$this->positions[5]->title) {
    $strtitle = JText::_($this->positions[5]->title);
} 

尝试这个

$strtitle = JText::_($this->positions[5]->title) || "Error bro";
于 2013-05-24T08:39:49.830 回答
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 等,这不是必需的,但可以帮助调试(尽管如果它是 int|double 它应该也可以通过

于 2013-05-24T08:37:16.793 回答