How to use mysql db to replace placeholders in php?

I have the database in MySql as well as we wish to keep the same webpage blueprint for any page, so we wish make use of the database to reinstate the "placeholders" in php. How do we do this? Can somebody yield the walkthrough?

One thought on “How to use mysql db to replace placeholders in php?

  1. If you have a table of CMS elements, fields "name, value" with values such as "site_name, My Awesome Site", I suggest:

    $a = mysql_query(‘SELECT * FROM elems’);
    while($b = mysql_fetch_assoc($a)) {
    $f[] = "pattern_start".$b['name']."pattern_end";
    $r[] = $b['value'];
    }
    $d = file_get_contents(‘your_template.html");
    $d = preg_replace($f, $r, $d);
    echo $d;

    I’m not sure what format your placeholders are in, but you’ll need to change the pattern bit. See php.net/pref_replace for details.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>