You can not write php code in either activity or data transform. These rules are java based rules, you have the step method called "java" to execute java code in activity. You dont have the same for PHP. And whatever you write in these rules compiled and executed on JRE.
You can use, HTML or HTML fragment are the places to compose your php code.
Instead of doing this, we recommend to get whatever you want from php as a REST or SOAP and integrate them into Pega using REST and SOAP connector respectively.