There is no correct syntax... you can't use [man]include[/man] to concatenate a file's value within a string. [man]file_get_contents/man, however, retrieves the contents of the file and returns it as a string.
[RESOLVED] Adding PHP Code to Variable
And you won't need the php tags
And if header.htm is a static HTML file, there's no reason to use the include/require functions.
I want to contact to a string...
is this on the right track??
$output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '.
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> '.
"\n\n".
'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> '.
"\n\n".
'<head> '.
"\n\n".
'<title>TA Generic Procedures - '.$title.'</title> '.
'<link rel="stylesheet" type="text/css" href="../css/screen.css" /> '.
'<script language="JavaScript" src="../menu.js"></script> '.
"\n\n".
'</head> '.
"\n\n".
"\n\n".
'<body> '.
"\n\n".
'.<div id="wrapper"> '.
"\n\n".
'<div id="header">
<?php
include(\'../header.htm\');
?>
</div> <!-- end Header --> '.
"\n\n".
'<div id="content"> '.
"\n\n".
'<h1>Fundshare</h1>
<?php
// load image
include('../display_img.php');
// connect to db
include('../db_connect.php');
$query = "SELECT $title, last_updated ".
"FROM $table";
$result = mssql_query($query) or die('Select Error');
//echo 'TR:'.$num_results = mssql_num_rows($result);
$row = mssql_fetch_array($result);
echo '<p class="edit_date">Last Updated: '.$row['last_updated'].'</p>';
echo stripslashes($title);
?>
</div> <!-- end Content --> ';
What are you trying to achieve? Did you want your $output variable to include the string literal
<?php
include(\'../header.htm\');
?>
? Or do you want your variable to include the contents of your header.htm file?
As liquorvicar asked, we need some clarification on whether you want this script to output the text "<?php include('header.htm') ?>" or if you actually want to load the header.htm file and output its data.
Also, it might be easier for you to use the HEREDOC syntax:
$output = <<<END_OF_STRING
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TA Generic Procedures - {$title}</title>
etc.
END_OF_STRING;
I'm guessing, what you try to achieve is to put what would be normally displayed in browser with include in some varible?
If so then output buffering is what you need:
$output = "whatever at the beginning";
ob_start(); //start output buffering
include('../header.html'); // this isn't sent to the browser, it's buffered instead
$output.=ob_get_contents(); //add what's in the buffer to the varible
ob_end_clean(); //turn off output buffering and clean the buffer (without sending to browser)
$output.="whatever should be next";
yes I want the string to output <?php include('header.htm') ?>
How do I do this? Thanks.
Tried HEREDOC...
<?php
$output = <<<PAGE_CONTENT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TA Generic Procedures - Operations Procedures - List of Funds</title>
<link rel="stylesheet" type="text/css" href="../css/screen.css" />
<script language="JavaScript" src="../menu.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
include('../header.htm');
?>
</div> <!-- end Header -->
<div id="content">
<h1>List of Funds & Relevant Dealing Cut-Off Points</h1>
<?php
// load image
include('../display_img.php');
// connect to db
include('../db_connect.php');
$query = "SELECT list_of_funds, last_updated ".
"FROM operations_procedures";
$result = mssql_query($query) or die('Select Error');
$row = mssql_fetch_array($result);
echo '<p class="edit_date">'.$row['last_updated'].'</p>';
echo $row['list_of_funds'];
?>
</div> <!-- end Content -->
<div id="sidecol">
<?php
include('../menu.htm');
?>
</div> <!-- end Side Column -->
</div> <!-- end Wrapper -->
</body>
</html>
PAGE_CONTENT;
I still don't understand what you try to achieve. But let's say you have
<?php
//header.php
echo "This is the first header line<br>";
echo "This is the second header line<br>";
echo "This is the third header line<br>";
?>
Thera are three possibilities what you can do:
1. echo string only
<?php
$output = htmlspecialchars("<?php include('header.php');?>");
echo $output;
?>
This will show that $output is
<?php include('header.php');?>
2. echo the content of the file
<?php
$output = nl2br(htmlspecialchars(file_get_contents('header.php')));
echo $output;
?>
This will show that $output is
<?php
//header.php
echo "This is the first header line<br>";
echo "This is the second header line<br>";
echo "This is the third header line<br>";
?>
3. echo the result of executing header.php
<?php
ob_start();
include('header.php');
$output = ob_get_contents();
ob_end_clean();
echo $output;
?>
This is the first header line<br>
This is the second header line<br>
This is the third header line<br>
There isn't much more you can do with that file and the varible
1/ I have a blank page template and want to make a copy of it as below...
$file = 'template.php'; //TEMPLATE
$newfile = $title.'.php'; // FILE COPY
$filedir = '../'.$folder.'/'.$newfile; // FILE DIRECTORY
// COPY OVER FILE TEMPLATE
if (!copy($file, $filedir)) {
//echo "failed to copy $file...\n";
}
else
{
//echo 'File Created.';
}
2/ Then I want to write $output to this new page...
// OPEN COPIED FILE
$fp = fopen($filedir, "w");
fwrite($fp, $output); // WRITE TO FILE
fclose($fp); // CLOSE FILE
The new page should contain this code...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TA Generic Procedures - Impress Procedures</title>
<link rel="stylesheet" type="text/css" href="../css/screen.css" />
<script language="JavaScript" src="../menu.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
include('../header.htm');
?>
</div> <!-- end Header -->
<div id="content">
<h1>Impress Procedures</h1>
<?php
// load image
include('../display_img.php');
// connect to db
include('../db_connect.php');
$query = "SELECT impress, last_updated ".
"FROM impress_procedures";
$result = mssql_query($query) or die('Select Error');
//echo 'TR:'.$num_results = mssql_num_rows($result);
$row = mssql_fetch_array($result);
echo '<p class="edit_date">Last Updated: '.$row['last_updated'].'</p>';
echo stripslashes($row['impress']);
?>
</div> <!-- end Content -->
<div id="sidecol">
<?php
include('../menu.htm');
?>
</div> <!-- end Side Column -->
</div> <!-- end Wrapper -->
</body>
</html>
so how do I assign this to $output????
sorry for not clearly explaining it.
Now I get it.
HEREDOC is a way to go. Just change all your $ there to \$ so it doesn't treat varibles as varibles.
$output = <<<PAGE_CONTENT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TA Generic Procedures - Operations Procedures - List of Funds</title>
<link rel="stylesheet" type="text/css" href="../css/screen.css" />
<script language="JavaScript" src="../menu.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
include('../header.htm');
?>
</div> <!-- end Header -->
<div id="content">
<h1>List of Funds & Relevant Dealing Cut-Off Points</h1>
<?php
// load image
include('../display_img.php');
// connect to db
include('../db_connect.php');
\$query = "SELECT list_of_funds, last_updated ".
"FROM operations_procedures";
\$result = mssql_query(\$query) or die('Select Error');
\$row = mssql_fetch_array(\$result);
echo '<p class="edit_date">'.\$row['last_updated'].'</p>';
echo \$row['list_of_funds'];
?>
</div> <!-- end Content -->
<div id="sidecol">
<?php
include('../menu.htm');
?>
</div> <!-- end Side Column -->
</div> <!-- end Wrapper -->
</body>
</html>
PAGE_CONTENT;
thanks!
How do I deal with the semicolon ; here... include('../header.htm');
Make sure you have no trailing spaces at the end of your heredoc.
PAGE_CONTENT;
When I copied and pasted it there was a space at the end of this line which was causing a problem.
still have same issue. Page is displayed as blank so there must be a syntax error.
<?php
//list($title1, $title2) = split('[/-._]', $title); // SET HEADING
$output = <<<PAGE_CONTENT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TA Generic Procedures - Operations Procedures - List of Funds</title>
<link rel="stylesheet" type="text/css" href="../css/screen.css" />
<script language="JavaScript" src="../menu.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
include('../header.htm');
?>
</div> <!-- end Header -->
<div id="content">
<h1>List of Funds & Relevant Dealing Cut-Off Points</h1>
<?php
// load image
include('../display_img.php');
// connect to db
include('../db_connect.php');
$query = "SELECT $title, last_updated ".
"FROM $table";
$result = mssql_query($query) or die('Select Error');
$row = mssql_fetch_array($result);
echo '<p class="edit_date">'.$row['last_updated'].'</p>';
echo $row['list_of_funds'];
?>
</div> <!-- end Content -->
<div id="sidecol">
<?php
include('../menu.htm');
?>
</div> <!-- end Side Column -->
</div> <!-- end Wrapper -->
</body>
</html>
PAGE_CONTENT;
?>
Then in the main page the above code is called here...
include('output.php');
Thanks!
Have you got display_errors and error_reporting turned on? That would tell you if you had a syntax error.
Otherwise, are you actually echo-ing the $output variable somewhere?
Get this error now...
Parse error: parse error, expecting T_STRING' or
T_VARIABLE' or `T_NUM_STRING' in C:\Inetpub\wwwroot\transfer_agency\new_page\output.php on line 55
What does this mean?
I set display_errors = On in my php.ini file
Don't forget you need to escape your variables with a backslash, i.e. "\$variable" rather than "$variable".
Line 55 is the ?> in this section...
<?php
include('../header.htm');
?>
No variables there and not sure what to do with the ?>
Any ideas? Thanks.
As I said, make sure you escape your dollar-signs. The next non-whitespace after line 55 is a variable with a dollar-sign.
sorry I don't see it???