Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: coopster & jatar k

How to add text inside variable?

   
11:41 am on Jan 13, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I have variable and inside this variable I like to set variable.

How to do this?
$myvariable1 = "$myvariable2 [0],facebook marketing";

How to do validated code for this that string will be seen with $myvariable2 [0]
12:03 pm on Jan 13, 2011 (gmt 0)

10+ Year Member



PHP eval is the function you need: [php.net...]
12:19 pm on Jan 13, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi all,

Unless I have misread the intention here, your nearly there with the example you have given:-

$myvariable1 = $myvariable2[0]."facebook marketing";

echo $myvariable1;

This would then print (for arguments sake) something like this:-

Contents of variable facebook marketing

if your joining variables together, you need to use the '.' full stop, this then concatenates the values together and stores them into the new name as you have assigned them to using the '=' assignment operator.

Cheers,
MRb
5:28 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



A second example, keeping in mind that scalar variables will interpolate with double quotes.

$fruits = Array (
'one' => 'cherries',
'two' => 'apples',
'three' => 'pears'
);

$animals = Array('lions','tigers','bears');

The following are equivalent, one may be more legible and easier to debug for you than the other depending on your style.

$output = "<p>Joebob walked his " . $animals[1] . " to the store to buy " . $fruits['one'] . ".</p>";

$myanimal = $animals[1];
$myfruit = $fruits['two'];

$output = "<p>Joebob walked his $myanimal to the store to buy $myfruit.</p>";
 

Featured Threads

Hot Threads This Week

Hot Threads This Month