Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to print php variable withing a variable?

Tags:

php

I have a very simple question. But is really making me crazy.

I have a statement say:

example and example with one php variable like $loggedin_user_name

First of all, I want to store the above sentence in MySQL database and then take it back whenever I want to print the above statement. It seems that their is no issue.
But when I tried to print data after extracting from database it is printing the same statement. But i guess, it has to print the logged in user name instead of $loggedin_user_name in the above statement.

So, is it possible to print the variable within the variable? If yes, please suggest a way.

like image 786
Hare Kumar Avatar asked Dec 29 '25 18:12

Hare Kumar


1 Answers

use sprintf()

$str = "example and example with one php variable like %s";

Then load it from database and fill

$out = sprintf($str, $loggedin_user_name);
like image 90
Your Common Sense Avatar answered Jan 01 '26 07:01

Your Common Sense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!