简体   繁体   中英

How do I echo a string containing a function?

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?

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

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

应该做到的。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM