在函数内调用函数

Xan*_*d94 1 php

我已经浏览了几个相关的问题,似乎无法看到问题!

以下两个函数都在我的函数include文件中,由于某种原因,我似乎无法使用check_orientation函数将scale返回到display_months_news函数.

我很确定我真的很遗憾.

display_news函数

function display_months_news()
{
    //header('Content-type: image/jpeg');
    $year = date("y");
    $year = "20" .$year;
    $month = date("m");
    if ($month) {
        switch ($month){
            case "01": $month = "January"; break;
            case "02": $month = "February"; break;
            case "03": $month = "March"; break;
            case "04": $month = "April"; break;
            case "05": $month = "May"; break;
            case "06": $month = "June"; break;
            case "07": $month = "July"; break;
            case "08": $month = "August"; break;
            case "09": $month = "September"; break;
            case "10": $month = "October"; break;
            case "11": $month = "November"; break;
            case "12": $month = "December"; break;
        }
    } else {
        echo '<p>The date field is empty.</p>';
    }
    $nowdate = $month." ".$year;

    $result = mysql_query("SELECT * FROM news ORDER BY sqldate DESC LIMIT 6") or die(mysql_error());

    while ($row = mysql_fetch_array($result)) {
        global $imgurl;
        $imgurl = $row['img1'];

        check_orientation4($imgurl);

        $comcount = comment_count($row['nid']);
        if ($comcount == NULL) {$comcount = 0;}

        echo '<div class="news-preview-container">';
        echo '<div class="news-preview-container-date">';
        echo "<P>" .$row['mmonth']. " ".$row['dday']. ", " .$row['yyear']. "</p><BR>";
        echo '</div>';
        echo '<div class="news-preview-container-title">';
        echo "<p><a href='article.php?id=" .$row['nid']."'>" .$row['title']."</a></p><BR>";
        echo '</div>';
        echo '<div class="news-preview-container-inner">';
        echo '<div class="news-preview-container-text">';
        echo '<p>'.ShortenText($row['body']).'</p>';
        echo '</div>';
        echo '<div class="news-preview-container-image"><img src="'.$imgurl.'"'.$scale.'"></div><BR></div>';
        echo '<div class="news-preview-container-bottombar">Posted in '.$row[tag].' / '.$comcount.' Comments</div>';
        echo '</div>';

    }
}
Run Code Online (Sandbox Code Playgroud)

和check_orientation函数

function check_orientation4($imgurls){

if ($imgurls == NULL){ echo "";  }
else {
        $imgurlshrunk = NULL;
        $maxsize = 120;
        $filename = NULL;
        $height = NULL;
        $width = NULL;
        $scale = NULL;
        $imgurlshrunk = $imgurls;
        $filename = basename($imgurlshrunk);
        $filename = "admin/uploads/" . $filename;
        list($width,$height,$type,$attr) = getimagesize("$filename");
        $wRatio = $maxsize / $width;
        $hRatio= $maxsize / $height;

    global $scale;

    if ( ($width <= $maxsize) && ($height <= $maxsize))
      {

        $scale = "";
        return $scale;
      }
    elseif ( ($wRatio * $height) < $maxsize) 
    { 
        $scale = "width = '100%'";  
        return $scale;
    }
    elseif  ($height == NULL)
    {

        echo "empty height";
    }
    else
    {
    global $height;
        $scale = "height = '100%'"; 
        return $scale; 
    }       }}
Run Code Online (Sandbox Code Playgroud)

提前感谢任何人指出我错过的愚蠢错误!

Yex*_*exo 5

您不存储check_orientation4($imgurl);任何地方的结果.尝试将该行更改为:

$scale = check_orientation4($imgurl);
Run Code Online (Sandbox Code Playgroud)