[thelist] PHP: How to include a variable in DB text?

**1st Vamp** wes at pmason.karoo.co.uk
Fri Jul 4 17:32:02 CDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: MD5

You can't really get PHP to see it as a variable, as a variable is an internal condition
to it's interpreter which is lost when it outputs flat data to mySQL.
However, you can make your PHP script handle the data as containing a variable, and then
replace that variable with your text, e.g.

Lorem ipsum dolor sit $var   --->  submit  --->

$text = 'Lorem ipsum dolor sit %foo%';

$foo = 'amet';
$text = str_replace('%foo%',$foo,$text);
echo $text;  // --->  Lorem ipsum dolor sit amet


HTH
- --
1stVamp
(Wesley Aaron Mason)

[ Site at somewhere :: http://1stvamp.org/ ]
[ Webcomic from nowhere :: http://gfbowl.com/ ]

Friday, July 4, 2003, 1:15:07 PM, m u i n a r wrote:

> Hello

> A PHP script retrieves a text from the MySQL database. What I want
> to accomplish is that I can include a variable in the text, i. e.
> type it into the DB form, say

> Lorem ipsum dolor sit $var   --->  submit  --->
> $text = "Lorem ipsum dolor sit $foo";

> ... and retrieve the text from the DB so that $foo is being
> filled in with its value:

> $foo = "amet";
> print( "$text" );   --->  Lorem ipsum dolor sit amet

</snip>

-----BEGIN PGP SIGNATURE-----
Version: 2.6

iQIMAwUAPwYAZetR7En81eJTAQEsdQ+46Cdizo3kzOZcpopDqLzLh9BfYTe+mesV
Mk2b5wbG1wBY1L+3NZJOuXFURqK/33aWee3EzMeKt4m/Rmf3hLVnmEtNpb/ElG1+
jZzJ84vHQ4y/lQwYIN5wd9ru4dhef1NxiZ7/nlaP01d+IhZrC+jq8VQe/E3tJGfZ
bnEHczcT7ZOGupPNgt+Px38bUoe8eX4TtfeDmN+JRz9BTy9T353dp9DXcJrFzpeg
zJ6v5+Whyst8XU6vF47pC/1Z0Xkr9FwcEdsSf+UxhRDihftZGSeP6rns7iqFpiBz
GVnBWgC6qrklQCrHLPr85sIkBzAHPb++MK8HnpBBq0GmwufL9V/atzWvFtAwR9vm
uG1MKj/0mojT5no0T32Ufo6W3n+ykdtfDqzz19swSesHBAk/rEvUb3C22Y2fGIyn
IJqVj37pWbakPJ7R3Rwl/2/JHT+rc7mk2LTu6bspL2anrpRPWyFB27q+7359yLuF
1xwVBXBDb4p1E8B4ZqYYx7M4F2jIJsYRJDX2VvY400yC3JsHdgFwq/da/S/FkwqF
0KSuCZWWPiGwmT/IhL5cOH2LoSA3EgD88Ls5yirdt7kykPK6XtoTiy7HXe56Pa8G
pR97LEyIdo4075xskJqsYlEMFspkZAG0GUQ96dclVRbjmQzoul9UxY9SZOi/s/o=
=iev2
-----END PGP SIGNATURE-----



More information about the thelist mailing list