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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.