Forum Moderators: coopster

Message Too Old, No Replies

Embedding an echo within DB text

Don't know why this won't work

         

neophyte

10:19 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



Hello All -

I have the need to echo information in various places from within pre-written text drawn from a db table. Text within the DB table is similar to this:

******************

<h1>Privacy Policy for <?php echo $companyName;?>.</h1>

<p>Some text here about some topic from <?php echo $companyName;?> relating to their privacy policy</p>

******************

When the text is displayed everything shows up between the html tags except the echoed variables which I find odd as if I were to type the same thing directly into a page (not drawn from a db table) then the contents of the VARs are displayed as expected.

When I check the source code of the page, the <?php echo $companyName;?> shows up in a pale blue color which I've also never seen before.

The only way I've found to make this work is to embed some kind of symbol (like an '*') where I need the var(s) to show up, draw the info from the table, and then replace the asterisk with the VAR. That works, but jeez, what a pain ... especially if there are numerous places that I need var information to be displayed.

As you can see in the example above, all of my text within the db table is already pre-formatted with html tags. Is this the problem?

Neophyte

sned

11:09 pm on Oct 1, 2007 (gmt 0)

10+ Year Member



I think your answer might lie in the eval [us3.php.net] function.

-sned

neophyte

5:11 am on Oct 2, 2007 (gmt 0)

10+ Year Member



sned -

Thanks for the tip on the eval() function! Works like a charm!

Follow-on question to you (or anyone else)...

From the documentation, I gather that eval() processes (evaluates) everything within a given string and then returns the string along with the contents of any $var found within the string.

If this is true, I'm imagining that display output may slow down if there was A LOT of text within a string to process.

If this is (at least theoretically) true, then is there another way to echo the contents of a $var found within a string of text drawn from a DB without a noticeable output performance hit?

Noephyte

jatar_k

2:09 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not that I can think of off the top of my head, you should benchmark eval to see if it is worth looking into more.