DataSpy Posted November 17, 2006 Share Posted November 17, 2006 Hello, I'm trying to include something inside an echo statement, also echo back a variable and am having some trouble.[code]<?php$index = $_GET['index'];if ($index==null){ header("Location: ?index=home"); exit;}elseif ($index=="home"){ echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title>untitled</title> </head> <link rel="stylesheet" type="text/css" href="css.css"><body bgcolor="B0C4DE" text="#000000" link="#000000" vlink="#000000" alink="#000000" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">echo "$var1";echo "$var2";include ("includes/footer.php");;}?>[/code]I know a way around it is to cut it off when the variable comes in and then do another elseif for the variables, but I was wondering if there was a better way. Any help greatly appretiated, thanx in advance! Link to comment https://forums.phpfreaks.com/topic/27532-how-to-include-something-inside-an-echo-statement/ Share on other sites More sharing options...
Seraskier Posted November 17, 2006 Share Posted November 17, 2006 it goes:[code]<?phpecho "Hello World";?>[/code] Link to comment https://forums.phpfreaks.com/topic/27532-how-to-include-something-inside-an-echo-statement/#findComment-125872 Share on other sites More sharing options...
Branden Wagner Posted November 17, 2006 Share Posted November 17, 2006 echo ' (all that stuff)';print(include(yourfile));i would assume that would work, ive never tried it. Link to comment https://forums.phpfreaks.com/topic/27532-how-to-include-something-inside-an-echo-statement/#findComment-125877 Share on other sites More sharing options...
nick89 Posted November 17, 2006 Share Posted November 17, 2006 Use an output buffer.From php.net:[code]<?php$string = get_include_contents('somefile.php');function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false;}?> [/code] Link to comment https://forums.phpfreaks.com/topic/27532-how-to-include-something-inside-an-echo-statement/#findComment-125891 Share on other sites More sharing options...
DataSpy Posted November 17, 2006 Author Share Posted November 17, 2006 Thanx, I figured out how to do it a different way. Link to comment https://forums.phpfreaks.com/topic/27532-how-to-include-something-inside-an-echo-statement/#findComment-125907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.