Forum Moderators: coopster

Message Too Old, No Replies

Storing string in database with variables

I want to have it substitute variables when I pull it out

         

mattx17

11:08 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



I have a string I want to store in a text field in a database. This string has the variable $Name in it. When I pull it out of the database, I want that variable to be substituted with the value I define before I print the string. It doesn't seem to work.

I tried looking into eval(), but that doesn't do what I want it to do. Has anyone who has done this before want to shed some light on how to do it?

Thanks!

Nutter

11:24 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



What about str_replace?

mattx17

11:32 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



Awesome! That worked. Thanks for your help.

Nutter

1:43 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



One tip, don't store the variable as something that looks like a PHP variable. Something like ##name## may lead to less confusion. Personally, I use variables that look like HTML comments <!--name--> . That way, if they don't get replaced, they don't show up on page; but I can still see 'em via view source.

I tend to confuse myself when I'm writing scripts, so I look for any way I can to make it less confusing.