Uutiset:

Join the Facebook Fan Page.

Main Menu
Advertisement:

Small PHP issue

Aloittaja perlgoodies, heinäkuu 26, 2007, 09:15:54 IP

« edellinen - seuraava »

perlgoodies

Apparently PHP differs from Perl far more than I thought and it doesn't seem to parse my variables in an echo line.


echo '
<table cellpadding="0" cellspacing="0" border="0" style="position: relative; top: -5px;">
<tr>
<a href="$scripturl?action=markasread;sa=all;sesc=$context[\'session_id\']">MARK ALL MESSAGES AS READ</a>
</tr>
</table>';


It literally prints $context, not the data, plus $scripturl and the box []

Jeff Lewis

If you use double quotes PHP can echo the value of the variable, for single quotes break out of the string then concatenate the variable like I've done here.

echo '
<table cellpadding="0" cellspacing="0" border="0" style="position: relative; top: -5px;">
<tr>
<a href="' . $scripturl . '?action=markasread;sa=all;sesc=' . $context['session_id'] . '">MARK ALL MESSAGES AS READ</a>
</tr>
</table>';
Co-Founder of SMF

perlgoodies

Oh wow, that's quite a disheartening fact about PHP then. I guess that's why most state and government offices still refuse to see it as a respectable language. Even something as trivial interpolation has to be removed from a print statement.

I do appreciate the help, I'll put it into action, but wow. It's almost like JavaScript all over again.

Jeff Lewis

Like I said, if you had used echo with double quotes it would have been fine.
Co-Founder of SMF

karlbenson

echo "show me my $string please";

Advertisement: