aaharrison
asked on
PHP quote problem
Hi, the following is a snippet from a large system I am creating. When I run this, nothing happens - nothing is output to the screen. What am I doing wrong? I would like to just print out the contents of $phpFile.
Thanks!
Thanks!
<?php
$primaryField[0] = "got it";
$fn = "more stuff";
$phpFile = "
<?php
if (checkRecord(".$primaryField[0].", ".$fn.", 'chklst') == 'no' && checkRecord($serverID, 'server', 'serverinfo') == 'no')
{
//insert into both databases
if (addToCHKLST() == 'success')
{
if (addToServerInfo() == 'success')
{
echo 'Add into both databases! ';
}
else
{
echo 'error occurred';
}
}
else
{
echo 'error occurred';
}
}
";
echo $phpFile;
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I meant to say <?php should be displayed as &lt?php (EE decoded the string I typed there)
ASKER
THANK YOU SO MUCH! That has been driving me crazy. I do have one more question though..
say for example where I have $serverID - how can I make it print $serverID and not interpolate it?
say for example where I have $serverID - how can I make it print $serverID and not interpolate it?
echo "\$serverID";
Use single quote instead of double quote.. So that the variable won't be expanded
ASKER
i have to be able to have half the string interpolate and the other half not - so when i surround the $serverID in single quotes it still gets interpolated.
Then you have to use double quotes and escape $ for the variables as shown by wizzie83..
<?php
$primaryField[0] = "got it";
$fn = "more stuff";
$phpFile = "
<?php
if (checkRecord(".$primaryField[0].", ".$fn.", 'chklst') == 'no' && checkRecord(\$serverID, 'server', 'serverinfo') == 'no')
{
//insert into both databases
if (addToCHKLST() == 'success')
{
if (addToServerInfo() == 'success')
{
echo 'Add into both databases! ';
}
else
{
echo 'error occurred';
}
}
else
{
echo 'error occurred';
}
}
";
echo htmlspecialchars($phpFile);
?>
ASKER
great thank you so much, you give great explanations!
ini_set("display_errors", 1);
And check for errors.