Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306258
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:16:02+00:00 2026-05-17T21:16:02+00:00

We have some bbcode and I’m trying to setup the ability for a certain

  • 0

We have some bbcode and I’m trying to setup the ability for a certain code to call a function that loads some images from our photo gallery. So if someone puts in an album number, it pulls 5 of the most recent photos out. When we call this function regularly (on another page, just as a regular php statement), it works as expected. But when we call this function through the preg_replace system, it loads the function at the top of the page.

See here: http://www.greendayauthority.com/news/1961/
The pumpkin images at the top of the site should be within the news post, below “Thanks to Marcus M. for sending the news.” – which is where I placed the bbcode [picvault]1[/picvault]

Here’s how we change out the values for the bbcode

$newsPost  = preg_replace(array_keys($bbcode), array_values($bbcode), $newsPost);

Here’s the portion of the $bbcode that calls our function

"/\[picvault\](.*?)\[\/picvault\]/e" => "relatedImages($1)",

And here’s the relatedImage function

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>";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:16:03+00:00Added an answer on May 17, 2026 at 9:16 pm

    If you use that function as callback it will output its html snippets right away. This happens because it uses echo. And when your preg_replace thus invokes the echo before the real page output starts, then the image html will preceed the rest of the page.

    Solution: make the relatedImages callback function use return instead of echo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code with the a structure similar to this function bbcode($Text) {
I have some javascript code that is used in a few different pages in
I have some automatic de-serialization code that will set an object's properties using KVC
I have some code that acquires a value for an enum: StringUtils.isEmpty(getEnumMember().value()); The supporting
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
We have some files on our website that users of our software can download.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.