0

Hello
I m having problem as below

I have a file named index.php and its code is

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Hello!</title>
</head>
<body>
<?php
$abc=file_get_contents("file.php") ;
echo $abc;
?>
</body>
</html>

and the code of file.php is

<?php
 echo "tushar";
 ?>

When I browes index.php its code is as below

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Hello!</title>
</head>
<body>
 <?php
 echo "tushar";
 ?>
</body>
</html>

But I want that output should be as below

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Hello!</title>
</head>
<body>
tushar
</body>
</html>

Help me and Explain me please

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mschroeder
0

file_get_contents does exactly what the function name says. It opens a file reads all of the content from the file and stores it into a variable etc for your later use.

If you want to use an additional php file within your index.php you want to use include/require (http://php.net/manual/en/function.include.php) There are also include_once and require_once variations but you can read the difference between them in the manual (http://www.php.net/manual/en/function.include-once.php)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.