0

I want to print a string in PHP that contains html, my code is:

<? if (!empty($dias)) {echo 'value="{$dias}"';}?>

but it prints value="{$dias}" What I want to achieve is something similar to

<? if (!empty($dias)) {echo 'value="'.$dias.'"';}?>

to print value="10". Of course I dont want to concatenate.

Ricardo Mehr
  • 310
  • 1
  • 3
  • 12

2 Answers2

2

Change quotes:

<? if (!empty($dias)) {echo "value='{$dias}'";}?>
// or
<? if (!empty($dias)) {echo "value=\"{$dias}\"";}?>

For more details see: What is the difference between single-quoted and double-quoted strings in PHP?

vstelmakh
  • 742
  • 1
  • 11
  • 19
1

Substitution only happens with strings enclosed in double quotes, so you'd use:

<? if (!empty($dias)) {echo "value=\"{$dias}\"";}?>
Brian Schantz
  • 509
  • 3
  • 9