Wednesday, 15 June 2011

How to write a if statement inside of a php variable that has html in it -



How to write a if statement inside of a php variable that has html in it -

i have php variable given html tag . need have php if status within tag, here have down:

$var = "<textarea" *if ($i=="1") { echo 'something' }* "id=\"id\" </textarea>";

what proper format this?

either build in stages:

$var = "<textarea"; if ($i=="1"){ $var .= 'something'; } $var .= "id=\"id\" </textarea>";

or utilize ternary operator:

$var = "<textarea" . ($i=="1" ? 'something' : '' ) . "id=\"id\" </textarea>";

php html

No comments:

Post a Comment