Using php include function in html in php variable
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>
Below is the code below that works, so don't post here.
Everything works instead of the include function.
source to share
Instead, 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 and is one of the preferred ways 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 contents of the file. This is where you store the content in a string. Thus, file_get_contents
is the correct option.
source to share
You can use get-content-content 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>';
source to share