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 7642083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:05:57+00:00 2026-05-31T09:05:57+00:00

I am storing HTML layouts within a MySQL database. These layouts may contain tags

  • 0

I am storing HTML layouts within a MySQL database. These layouts may contain tags within the HTML as show below..

{site.poll="fred,joe,john"}

and

{site.layout.header}

Currently i am searching the HTML template by executing multiple preg_matches to identify the tags, looping through the array then executing a str_replace(), replacing with another partial html template also pulled back from the db.. Example below..

  if (preg_match_all('/{site\.layout\.(.)*}/', $data, $match) != FALSE)
  {
     foreach($match[0] as $value)
     {
        $value = trim($value, '{}');

        $tmp_store   = explode('.', $value);
        $tmp_partial = $this->parse($this->get_layout(end($tmp_store)));
        $data        = str_replace('{'. $value .'}', $tmp_partial, $data);
     }
  }

I would need to execute a regex for each tag i required, then execute a str_replace on each instance of that tag.. The same again would need doing for each required partial template..
To me, this is all seeming to get heavy..

Is there a better way of doing this?

Thanks in advance..

Edit: I do not want to use an existing library, i would like to do this task myself and learn in the process..

  • 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-31T09:05:59+00:00Added an answer on May 31, 2026 at 9:05 am

    I don’t expect this to answer your question as such, but thought it might give you something else to think about. Some code I’ve got for when my template class is overkill.

    function replace_tags(&$xhtml, $tags) {
        if( is_array($tags) && count($tags) > 0 )
            foreach ($tags as $tag => $data) {
                $xhtml = str_replace("{{" . $tag . "}}", $data, $xhtml);
            }
    
        if( $xhtml ) return $xhtml;
    }
    
    $tpl = "/templates/index.xhtml";
    $tags = array(
        "css"             => null,
        "js"              => null,
        "main_content"    => null
    );
    
    $tags['main_content'] = file_get_contents("/home/main.xhtml");
    
    echo replace_tags(file_get_contents($tpl), $tags);
    

    edit

    Thought I’d clarify on the reason the function receives $xhtml by reference, and also returns $xhtml. Basically just to make it dual purpose.

    //Usage at the end of a page
    echo replace_tags(file_get_contents($tpl), $tags);
    
    //Usage for template in template
    $tags['menu'] = file_get_contents($menu_tpl);
    replace_tags($tags['menu'], $tags);
    
    echo replace_tags(file_get_contents($tpl), $tags);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: Storing arbitrary info in HTML tags for JavaScript? What are the concrete
What column type should I use for storing html content from a website with
I am storing a number of HTML blocks inside a CMS for reasons of
I'm using CF8 and SQL2000. I'm storing a bunch of HTML in a Text
I storing html to a text field. The html is a fully formed webpage
I have the below code to parse an section of an html page. What
I'm looking for a solution to manage a one-to-many relation within an HTML form
I have the following: string html_string = http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=pharma; string html; html = new WebClient().DownloadString(html_string);
Given an HTML string like: <span class=findme id=31313131313>The Goods</span> What kind of REGEX in
I have a html string held in memory after transforming to my desired template

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.