Reputation: 1878
I've got a PHP page (content.php), containing plain HTML and content delivered by PHP variables
<html>
<head>
</head>
<body>
<h1><?php echo $title; ?></h1>
</body>
</html>
Then there is another PHP page, where I need the contents of content.php in a String, but already processed by the PHP parser. I already tried the file_get_contents() function, but this gives the raw output (PHP not processed). What I'm looking for, is this:
$var contents = somefunction('contents.php')
with content:
<html>
<head>
</head>
<body>
<h1>Title</h1>
</body>
</html>
Any help much appreciated!
Upvotes: 0
Views: 115
Reputation: 1471
Try:
ob_start();
include ('contents.php');
$html = ob_get_clean();
ob_end_clean();
Upvotes: 1
Reputation: 507
either i am missing something badly here or else instead of using a function, in your second page why not just directly assign the contents to a string like this:
$my_String = "<html>
<head>
</head>
<body>
<h1>". $title ."</h1>
</body>
</html>";
Upvotes: 0
Reputation: 324610
Have you tried include
? Alternatively, if you need to get it from "outside" (like if you loaded it in your browser) use file_get_contents
with the full http://example.com/filename.php
URL.
Upvotes: 0