2

i am doing something like this

   $some_var='<!DOCTYPE html>
              <head>
              <title>questions '.$suto.'</title>
              <meta charset="utf-8" />
              <meta name="description" content="question need to'. $suto.'">
              '. include ("header.php") .'
              <body>       

There is more code below which is working that's why not posting here.

Everything works instead the include function.

0

2 Answers 2

3

Instead of include() you can use file_get_contents() like,

$some_var='<!DOCTYPE html>
    <head>
            <title>questions '.$suto.'</title>
             <meta charset="utf-8" />
             <meta name="description" content="question need to'.$suto.'">'.file_get_contents("header.php").'
    <body>   

file_get_contents() is a PHP function which is one of the preferred way to read the contents of a file into a string.

include() will parse PHP code inside the included file. And file_get_contents() will return the content of the file. Here, you are storing the content to a string. So the file_get_contents is the right option.

Sign up to request clarification or add additional context in comments.

7 Comments

ty jenz it works but why include function failed in this case
@sukhjitdhot..Sorry for the delay. Please check my updated answer for more details.
thanks jenz file-get-contents ("../header.php") is not working can you suggest how to select header from previous directory
If header.php resides in the folder below then ("../header.php") should work.
that's what exactly i hoped but it is not working for some reason.
|
0

You could use file-get-contents function (http://php.net/manual/en/function.file-get-contents.php)

$some_var='<!DOCTYPE html>
           <head>
           <title>questions '.$suto.'</title>
           <meta charset="utf-8" />
           <meta name="description" content="question need to'. $suto.'">
           '. file-get-contents ("header.php") .'

           <body>';     

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.