Home : phpBB : About

phpBB » phpBB 3 & XML Processing Instructions

phpBB 3 sensibly strips [1] any PHP tags in templates ;

Example 1 - PHP Code
<? function delete_everything_in_the_database() ?>

But as they are in the same format as the short tags allowed by PHP, this also removes any XML processing instructions used in RSS, Atom file generation, etc. ;

Example 2 - XML Code
<?xml version="1.0" encoding="utf-8"?>

Whilst you could adapt the phpBB code to check for short tags being set on, you would also need to put such checks in the code where you were using templates with the XML processing instructions.

There are a few solutions, the first being to prepend the processing instruction to the returned code from the “assign_display” [2] function ;

Example 3 - PHP Code
$content = $template->assign_display('body');
$content = '<?xml version="1.0" encoding="utf-8"?>'."\n".$content;

The second and ordinarily preferable method is to adapt your template(s) and assign the processing instruction using either the “assign_var” [2] or “assign_vars” [2] functions to a template variable ;

Example 5 - PHP Code
$template->assign_vars(
  array(
    'XML_PI' => '<?xml version="1.0" encoding="utf-8"?>'."\n",
   
'CHANNEL_TITLE' => 'Some title…'
  )
);
Example 4 - Template Code
{XML_PI}
<rss version="2.0">

</rss>

Either of these solutions also allows for the processing instruction to be dynamically tailored to suit encoding changes, etc.

Notes

[1] function remove_php_tags in <PHPBB_ROOT_PATH>/includes/functions_template.php.

[2] In <PHPBB_ROOT_PATH>/includes/template.php.

Home : Top

Last Updated: May 26, 2009 2:49 PM :: © 2009 by Darren Burnhill