Include in block

Include in block

by Jean-Marc Loisil -
Number of replies: 2

Hi,

I am working on a custom block and I want to include a distant php file in in.

Th following code doesnt display the included text in the right position (on top of the block) :

$this->content->text=include('http://www.blabla.com/text.php');

Any clue

Thanx

Average of ratings: -
In reply to Jean-Marc Loisil

Re: Include in block

by John Papaioannou -
First of all, for that include to work you have to let PHP transparently open remote files through the HTTP and other protocols, which could be a security risk for your server.

To do what you want, you have two options:

  1. Change your remote PHP script to write its output to a variable. You would then do something like:

    include('some_file.php'); // This sets $outputhtml
    $this->content->text = $outputhtml;
  2. Use PHP's output buffering functions, e.g.:

    ob_start();
    include('some_file.php');
    $outputhtml = ob_get_clean(); // ob_get_clean requires PHP >= 4.3.0
    $this->content->text = $outputhtml;

Jon