Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: perlgoodies - heinäkuu 26, 2007, 09:15:54 IP

Otsikko: Small PHP issue
Kirjoitti: perlgoodies - heinäkuu 26, 2007, 09:15:54 IP
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 []
Otsikko: Re: Small PHP issue
Kirjoitti: Jeff Lewis - heinäkuu 26, 2007, 09:30:06 IP
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>';
Otsikko: Re: Small PHP issue
Kirjoitti: perlgoodies - heinäkuu 26, 2007, 09:36:11 IP
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.
Otsikko: Re: Small PHP issue
Kirjoitti: Jeff Lewis - heinäkuu 26, 2007, 09:51:23 IP
Like I said, if you had used echo with double quotes it would have been fine.
Otsikko: Re: Small PHP issue
Kirjoitti: karlbenson - heinäkuu 26, 2007, 10:05:32 IP
echo "show me my $string please";