Facebook PHP XHP RPM on CentOS 5.5

A few days ago, Facebook released XHP, a PHP extension, which allows defining XML directly in PHP blocks, allowing you to “use PHP as a stricter templating engine”.

It seems a bit strange to be coding XML tags directly in PHP blocks, but it adds features such as automatic escaping, and the ability to manipuate the tags, and how they render.

I’ve compiled experimental RPMs, and put them in the Webtatic yum repository. These are compiled against PHP 5.3, which I also have in my repository.

I cannot guarantee the build of the exension is stable, as I had to add a few patches of my own to the source to get it to compile, so I don’t recommend you install it on a production site.

To install, first upgrade your PHP to 5.3, as detailed in my PHP 5.3 on CentOS post.

Then install the extension, and then you’re done:

yum install --enablerepo=webtatic php-xhp

To test if it is set up correctly, run the following:

php -r 'echo "XHP!\n"; exit; <a />;'

Currently XHP requires you to include a PHP file (xhp/init.php), which is installed in the include path, to define all the default elements e.g.:

require 'xhp/init.php';
 
$href = 'http://www.webtatic.com';
echo <a href={$href}>Webtatic.com</a>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">