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

  • Home
  • SEARCH
  • 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 9305661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:58:45+00:00 2026-06-18T23:58:45+00:00

How can preg_replace call a function in the same class? I have tried the

  • 0

How can preg_replace call a function in the same class?

I have tried the following:

<?php

defined('IN_SCRIPT') or exit;

class Templates {

    protected $db;

    function __construct(&$db) {
        $this->db = &$db;
        $settings = new Settings($this->db);
        $gamebase = new Gamebase($this->db);
        $this->theme = $settings->theme_id;
        $this->gameid = $gamebase->getId();
    }

    function get($template) {
        $query = $this->db->execute("
            SELECT `main_templates`.`content`
            FROM `main_templates`
            INNER JOIN `main_templates_group`
                ON `main_templates_group`.`id` = `main_templates`.`gid`
            INNER JOIN `main_themes`
                ON `main_themes`.`id` = `main_templates_group`.`tid`
            WHERE
                `main_themes`.`id` = '".$this->theme."'
            &&
                `main_templates`.`name` = '".$template."'
        ");
        while ($templates = mysql_fetch_array($query)) {
            $content = $templates['content'];

            // Outcomment
            $pattern[] = "/\/\*(.*?)\*\//is";
            $replace[] = "";

            // Call a template
            $pattern[] = "/\[template\](.*?)\[\/template\]/is";
            $replace[] = $this->get('header');

            $content = preg_replace($pattern, $replace, $content);
            return $content;
        }
    }
}

But that just comes out with the following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@site.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

As soon as I outcomment this:

// Call a template
$pattern[] = "/\[template\](.*?)\[\/template\]/is";
$replace[] = $this->get('header');

Then it works. But i need it to run a function.

And actually I don’t need it to run the function with the header value in, I need the content between [template] and [/template] to be in the function.

Does anyone have any idea how to do this?

  • 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-06-18T23:58:46+00:00Added an answer on June 18, 2026 at 11:58 pm

    I think your script might be entering an infinite loop. If you look in your get function, you’re calling this:

    $replace[] = $this->get('header');
    

    So in the middle of a get call, you’re pulling in the header. This then executes the exact same function which will itself pull in the header, over and over, over and over. You might want to disable this line for when $template is ‘header’:

    while ($templates = mysql_fetch_array($query)) {   
    
       $content = $templates['content'];
    
       // If this is the header, stop here
       if ($template == 'header') 
          return $content;
    
       // Rest of loop...
    }
    

    If you want to perform regular expressions, add this after the while loop:

    if ($template == 'header') {
       $pattern = "/\[template\](.*?)\[\/template\]/is";
       $replace = 'WHATEVER YOU WANT TO REPLACE IT WITH';
       return preg_replace($pattern, $replace, $templates['content']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: <?php function calculate_string( $mathString ) { $mathString = trim($mathString); //
How can I utilize preg_replace in PHP to parse a url. Say I have
I can't quite figure out the right pattern to use with PHP's preg_replace function.
In PHP, you have preg_replace($patterns, $replacements, $string) , where you can make all your
I have a problem with the function preg_replace_callback() in PHP. I want to call
Is there any reason why I can't use preg_replace inside a static function? when
Can someone help debug this error? Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat
How can I use preg_replace to do this: I want to replace: <a href=index.php?option=example1&view=something>
In PHP, I can do: $str = preg_replace(/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/, 'a', $str); means that in a
For some reason my preg_replace call is not working, I have check everything I

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.