loading...

re: 5 bad habits to lose in PHP VIEW POST

FULL DISCUSSION
 

For the fourth one, I rather prefer string interpolation.

echo "Hello {$name}" ;
 

I like string interpolation too whenever I can get away with it.

 

String interpolation gets weird if your string contains quotes, though

printf('<a href="%s"></a>',$link);

vs

echo "<a href=\"{$link}\"></a>";

Of course one could write it this way

echo "<a href='{$link}'></a>";
  • but for some reasons I don't like single quotes for html attributes :)

At the end and in this case, whatever works best/is the easiest to write and read. sprintf with many vars is a pain to read.

 

String interpolation works to in this case. 👍
I am used to (s)printf when
I want to translate string which contains variables with gettext and also to format float.

code of conduct - report abuse