-1

Is it possible to assign the contents of a simple html page to a variable?

$mail = (require("mail.html")); 

The purpose is to include text from a web page in an email instead of text from a database.

simeg
  • 1,889
  • 2
  • 26
  • 34
sharon
  • 55
  • 7
  • 2
    [file_get_contents](http://php.net/manual/en/function.file-get-contents.php)? – Bogdan Kuštan Dec 29 '14 at 10:54
  • 1
    I found the same question on this web ... http://stackoverflow.com/questions/5948395/require-include-into-variable – Apuig Dec 29 '14 at 10:59
  • Many thanks Barmer and others. file_get_contents works great. – sharon Dec 29 '14 at 11:05
  • Apuig: Have you marked me down? The accepted answer of the link is entirely different from the one barmer and aWebDeveloper gave which is very neat and what I was after. True, 6 answers down is a post but that was never accept nor commented on. I think this question / answer will be useful to others too. – sharon Dec 29 '14 at 11:15

4 Answers4

4

You can use file_get_contents to read the contents of a web page:

$mail = file_get_contents('mail.html');
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

Use file_get_contents(). You can use this function to get content into a variable

$mail = file_get_contents("mail.html");

http://php.net/manual/en/function.file-get-contents.php

or use readfile (not recommneded though)

ob_start();
readfile("text.txt");
$data = ob_get_clean();
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242
0

Try this

 ob_start();
 require_once "mail.html";
 $mail = ob_get_contents();
 ob_end_clean();
Bhavya Shaktawat
  • 2,504
  • 1
  • 13
  • 11
0

your requirment needed file_get_contents().try below code:

$mail = file_get_contents('mail.html');
Priyank
  • 3,778
  • 3
  • 29
  • 48