This can be done (remember Dimitre that if he asks about PHP, he will almost certainly be limited to XSLT 1.0, and FXSL is not quite what he is after).
Firstly, if you plan to write PHP yourself and use it as part of the document processing flow, this is probably a poor choice of language for this. In the case where you just want to extend the tiny bit XSL functionality with a few PHP functions from your own or useful library functions, such as preg_replace, so you can call them from your XSLT, you are absolutely fine if you know that these are in advance: you export PHP functions to XSLT and just call them from there.
If the code you want to execute is different for each document, however, it becomes more complicated (i.e. to process the instructions in the documents you are trying to process that contain PHP, and you want the XSLT script to evaluate your document for follow the processing instructions). Try and drop the functions in the well-known set and just call them from PHP, but if you cannot and want to try, it is up to the hacker.
(I assume that you know about the way to export functions to XSLT in PHP: you execute some regular PHP functions, you export them to an XSLT script using registerPHPFunctions, and they just call them functions inside XSLT. Beaten path, check the docs.)
Let's get back to executing the PHP code in your PI documents from an XSLT script.
(I didnβt do it myself, but it should not be so difficult to implement.) I believe that this cannot be done in one pass. You must call the XSLT processor, and whenever you click on the PHP you want to run, enter a marker tag (for example, <phpmarker md5ofcode="php:md5(...)"> ) and pass the code back to the calling PHP. Hacky, but potentially livable, would be to put it in an xsl: message and catch it from a custom handler in PHP.
When the first run is complete, do a little string manipulation to make a wrapper function around each block of code that you grab, evaluate that line to create functions, export them to the XSLT engine, and then call it again with a second XSLT script that will quote marker nodes and call PHP on their contents.
Nasty? Yes. You might want to explain why you want this, but it should be possible (in two passes) to make it work.
Edit : After rereading my question a few more times, I am increasingly embarrassed. Are you sure you want to use PI in your XSLT? PI go in documents explaining how to handle them. If PHP is intended to be used in an XSLT file and that is not a typo, I think you might be a little confused, and it is just a simple application for PHP vanillin registerPHPFunctions. You just need to put PHP in a separate file and call it from XSLT, which is not a huge burden, since XSLT scripts do not have to contain many functions before they are large enough to split into two files.