Link to home
Start Free TrialLog in
Avatar of aaharrison
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!

<?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;
?>

Open in new window

Avatar of wizzie83
wizzie83

error_reporting(E_ALL);
ini_set("display_errors", 1);

And check for errors.
ASKER CERTIFIED SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I meant to say <?php should be displayed as &amp;lt?php (EE decoded the string I typed there)
Avatar of aaharrison

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?
echo "\$serverID";
Use single quote instead of double quote.. So that the variable won't be expanded
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);
?>

Open in new window

great thank you so much, you give great explanations!