PDA

View Full Version : Including output of PHP file in custom template? [closed]


saajjj
12-31-2009, 03:24 PM
Hi Guys,
I've read plenty of threads on how to insert PHP code in a custom vBulletin page. However, I'm trying to insert the output of a PHP file inside a custom template. This custom template is itself inside the header template.

What I've got right now is a custom template which creates a place-holder inside the header.
The header template just has the following added:
{vb:raw showCustomTemplate}

This place-holder needs to be populated with the output of a PHP file. Within my custom template I have some styling information and the statement:
{vb:raw myPHPFileOutput}

The question, I suppose is, how do I connect myPHPFileOutput to read whatever myPHPFile.php outputs? AFAIK, a template can't execute php code, otherwise I could've simply done an 'include' there.

Any help appreciated.

Edit: Let's assume the php file is:
<?php
echo("hello world");
?>

--------------- Added 1262281885 at 1262281885 ---------------

I've added a new plugin which helps me somewhat but not entirely:

ob_start();
include 'myPHPFile.php';
$include_contents = ob_get_contents();
ob_end_flush();

vB_Template::preRegister('myCustomTemplate',array( 'php_file_output' => $include_contents));

The above does work but I see 'hello world' in two places.
1. Inside the header place-holder, which is correct
2. Right at the top of the page, which is wrong.

I have a feeling this isn't the correct approach.

--------------- Added 1262282717 at 1262282717 ---------------

I've changed the new plugin code from ob_end_flush() to ob_end_clean().

This has got rid of the output appearing right at the top of the page (#2) however, I've got these strange characters before the output of my php file. The place-holder in the header now reads:
hello world

--------------- Added 1262284458 at 1262284458 ---------------

Right so those strange characters represent the Byte Order Mark (BOM). I got rid of those by converting my php file to save without the BOM. I really don't see why this should solve the problem since I'm only including what's being output by the PHP file; nevertheless, it does work.

It seems all my problems are solved. Consider this thread closed :)