div img src不显示随机图像

时间:2018-12-31 15:11:25

标签: php image random

我的页面php部分中有用于随机图片的代码

$imagesDir = 'images/eggs/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];

它将显示带有此代码的图像

echo "<img src='$randomImage'>";

但是当我尝试在页面的正文部分执行此操作

<body>';
}
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
echo !empty($settings['forum_width']) ? '
<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
<div class="forest">
    <div id="egg1"></div>
</div>
<div id="header"><div class="frame">
    <div id="baloon1">
            <img src="egg.php"/> //tried including seperate php code
            <img src="<?php echo $randomImage ?>"> //php on same page
    </div>

我正在显示图像源...%3C?php ... 对我要去哪里哪里有帮助吗?

1 个答案:

答案 0 :(得分:-1)

尝试这种方式:

  function template_body_above()
    {
        global $context, $settings, $options, $scripturl, $txt, $modSettings;
        echo  ( (!empty($settings['forum_width'])) ?  '<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '')  .

                '
                <div class="forest">
                    <div id="egg1"></div>
                </div>
                <div id="header"><div class="frame">
                    <div id="baloon1">
                        <img src="' . $randomImage  . '">
                </div>