Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从preg_replace调用php函数会导致在页面顶部加载该函数_Php_Function_Preg Replace - Fatal编程技术网

从preg_replace调用php函数会导致在页面顶部加载该函数

从preg_replace调用php函数会导致在页面顶部加载该函数,php,function,preg-replace,Php,Function,Preg Replace,我们有一些bbcode,我正在尝试设置特定代码调用函数的功能,该函数从我们的照片库加载一些图像。因此,如果有人输入相册号码,它会从中取出5张最近的照片。当我们定期调用这个函数时(在另一个页面上,就像一个常规php语句一样),它会按预期工作。但是当我们通过preg_replace系统调用此函数时,它会在页面顶部加载该函数 请看这里: 网站顶部的南瓜图片应该放在新闻帖子的下面,“感谢马库斯·M.发送新闻。”-这是我放置bbcode[picvault]1[/picvault]的地方 下面是我们如何更改

我们有一些bbcode,我正在尝试设置特定代码调用函数的功能,该函数从我们的照片库加载一些图像。因此,如果有人输入相册号码,它会从中取出5张最近的照片。当我们定期调用这个函数时(在另一个页面上,就像一个常规php语句一样),它会按预期工作。但是当我们通过preg_replace系统调用此函数时,它会在页面顶部加载该函数

请看这里: 网站顶部的南瓜图片应该放在新闻帖子的下面,“感谢马库斯·M.发送新闻。”-这是我放置bbcode[picvault]1[/picvault]的地方

下面是我们如何更改bbcode的值

$newsPost  = preg_replace(array_keys($bbcode), array_values($bbcode), $newsPost);
下面是$bbcode中调用我们函数的部分

"/\[picvault\](.*?)\[\/picvault\]/e" => "relatedImages($1)",
这是相关的图像函数

function relatedImages($albumID) {

    $queryImage = mysql_query("SELECT * FROM cpg140_pictures WHERE aid = $albumID ORDER BY pid DESC LIMIT 5");

    echo "<div class='relatedImages'>";
    while($images = mysql_fetch_array($queryImage)) {

            $relImgPath = $images['filepath'];
            $relImgName = $images['filename'];
            $relThumbImgUrl = "http://www.greendayauthority.com/Picture_Vault/albums/$relImgPath/thumb_$relImgName";
            $relFullImgUrl = "http://www.greendayauthority.com/Picture_Vault/albums/$relImgPath/$relImgName";

        echo "<div class='relImage'>
                        <a href='$relFullImgUrl' rel='lightbox-$albumID'><img src='$relThumbImgUrl'></a>
                    </div>";
    }

    echo " <div class='relImage'>
                        <a href='http://www.greendayauthority.com/Picture_Vault/thumbnails.php?album=$albumID' target='_top'><img src='http://www.greendayauthority.com/images/viewmorephotos.png'></a>
                 </div>";
    echo "</div>";
}
函数相关图像($albumID){
$queryImage=mysql_查询(“从cpg140_图片中选择*,其中aid=$albumID按pid描述顺序限制5”);
回声“;
而($images=mysql\u fetch\u数组($queryImage)){
$relImgPath=$images['filepath'];
$relImgName=$images['filename'];
$relThumbImgUrl=”http://www.greendayauthority.com/Picture_Vault/albums/$relImgPath/thumb_$relImgName”;
$relFullImgUrl=”http://www.greendayauthority.com/Picture_Vault/albums/$relImgPath/$relImgName”;
回声“
";
}
回声“
";
回声“;
}

如果将该函数用作回调函数,它将立即输出其html片段。这是因为它使用了
echo
。当preg_replace在实际页面输出开始之前调用echo时,图像html将优先于页面的其余部分

解决方案:使relatedImages回调函数使用
return
而不是echo