eng_mazzy
eng_mazzy

Reputation: 1049

html and php code mixed in a php variable

I have a php variable and I had to insert into it html code with another variable. ie:

myarray['foo'] = "<p><? echo $var; ?></p>"

but in this way it doesnt' work. How could escape it correctly?

Upvotes: 0

Views: 95

Answers (3)

davidethell
davidethell

Reputation: 12018

Just do:

myarray['foo'] = "<p>$var</p>"

PHP handles all the parsing for you.

EDIT:

From your comment about the array, you could print the raw contents of the array (not very helpful for an app, but fine for debugging):

myarray['foo'] = "<p>".print_r($var, true)."</p>";

Upvotes: 2

lpostula
lpostula

Reputation: 584

Can't you just do

my_array['foo'] = '<p>'.$var.'</p>';

Upvotes: 1

Dave Kasper
Dave Kasper

Reputation: 1389

myarray['foo'] = "<p>" . $var . "</p>"

Upvotes: 1

Related Questions