/    Sign up×
Community /Pin to ProfileBookmark

Echoing text with variables inside content

Hello,

I could just be having a severe brain-freeze here, but i’m basically echoing out a “text” field from a mysql database which contains some text plus some variables. for example:

(geometry mysql table, id | product | geometry)

“1”, “mountain”, “$vocab_frame_size goes to a maximum of $maximum_size”;

(the content is dummy, but its basically along those lines.)

I can’t get it to echo out the values of those variables (which are declared within the php document.)

How can i get the variable values inserted?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@MarPloAug 23.2011 — Hy,

Try use dynamic variable ($$). But you must delete the $ character from the string with the name that represents the variable.

Example:
<i>
</i>&lt;?php
$variable = 'value';
$column = 'variable';

echo $$column; // value
?&gt;
Copy linkTweet thisAlerts:
@copesauthorAug 23.2011 — Hmm maybe i didn't explain myself well.

in php i'm doing this:

[code=php]$query = 'SELECT * FROM bike_geometry WHERE name="'.$user_model.'"';
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$model_geometry_long = $row['longdesc'];

echo $model_geometry_long;

$variable = "some text";
[/code]


What is contained with the database within 'longdesc' is:

"lorem ipsum bla bla.. [B]$variable[/B] lorem ipsum bla bla."

I want $variable to display it's content when i echo $model_geometry_long; but currently it just displays $variable as it's written inside 'longdesc'
Copy linkTweet thisAlerts:
@NoasITAug 23.2011 — you could do a replacement:

[code=php]
$query = 'SELECT * FROM bike_geometry WHERE name="'.$user_model.'"';
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$model_geometry_long = $row['longdesc'];
$new_long = str_replace('$variable','some text',$model_geometry_long);

echo $new_long;
[/code]


HTH
Copy linkTweet thisAlerts:
@copesauthorAug 24.2011 — That's a good suggestion NoasIT!

I'll use a couple of arrays and that should do the job nicely.

Thanks
×

Success!

Help @copes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...