Has anyone else run into this problem...

I am starting to store my web content in a database. Both automated email responses, actual web page content, etc...

But the problem I'm running into is that any PHP code that is embeded in the content isn't parsed when I pull it out.

For example, in an email I have "Hi $member[fname],"

Obviously I want to parse $member[fname] with the members first name.

When I hard code the email verbage right into the actual script to process the email it parses fine... but when I pull the email content from a dbase it just plops the content in and doesn't parse the variables. The same holds true for web content.

Any ideas? Suggestions?

    yep, I had that problem at one stage. I was storing full SQL queries in the database, but with $variables in my WHERE clauses etc...... very simple way to do it. Basically you have to tell PHP to run over the code twice.... once to re-populate your variables with their values within that scope, and then you can do as you please with it.

    so say you have a variable called $stuff and it contains the following string:

    Hello, my name is $name

    ...and in the current scope, $name is equal to rich81.

    now, if you just print($stuff);, the output will be:

    Hello, my name is $name

    but if you do the following:

    eval("\$stuff=\"$stuff\";");
    print($stuff);

    ... php will run over the code once BEFORE printing it. the slashes in the eval() function look messy but it's necessary.

    so the sequence of events:

    Hello, my name is $name
    <eval the string>
    Hello, my name is rich81
    <print the string>

      eval ("?>" . $yourPHPandHTMLcode . "<?php");

      This assumes that the stuff pulled from the database ( $yourPHPandHTMLcode ) is proper, ie has proper <?php and ?> tags.

        Write a Reply...