-1

I am using an ifelse statement to echo a string. However, when incorporating a function, I receive a syntax error.

This works >

echo "<p>Remarks: {$row['REM']}</p>"

This does not work >

echo "<p>Remarks: {ucfirst($row['REM'])}</p>"

What am I missing to incorporate the "ucfirst( )" function?

noy-hadar
  • 169
  • 1
  • 12

3 Answers3

3

Try :

echo '<p>Remarks: '.ucfirst($row['REM']).'</p>';

EDIT : if i remember good, functions are not evaluated by PHP in strings under double quotes ", while nothing is evaluated in strings under simple quotes '

EDIT 2 : Found a nice explaination in here, see this stackoverflow answer

Community
  • 1
  • 1
Bobot
  • 1,118
  • 8
  • 19
1
echo "<p>Remarks: ".ucfirst(row['REM'])."</p>";

Should do the trick.

MatthewJames
  • 112
  • 1
  • 10
  • 1
    yep, just want to precise that simple quotes are faster than double ones, cuz PHP does not evaluate them, so if you don't need to use vars in the string, do not use double quotes ;P (thats nothing but in long scripts that saves some precious milliseconds :P) – Bobot Jul 04 '14 at 02:20
0

If you REALLY need this...

$row['REM'] = 'qwe';

$ucfirst = 'ucfirst';
echo "<p>Remarks: {$ucfirst($row['REM'])}</p>";

or even

echo "<p>Remarks: {${$ucfirst='ucfirst'}($row['REM'])}</p>";

make it harder

echo "<p>Remarks: {${${ucfirst($row['REM'])}=ucfirst($row['REM'])}}</p>";

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

sectus
  • 15,605
  • 5
  • 55
  • 97