12.9. String Substitutions
It is possible to set up replacements, or substitutions, that are performed on files when installed. This is useful to keep default path names and other configuration data in sync with the user's PEAR configuration, to invoke PHP with the right PATH, and more.
12.9.1. Element: <replace>
The replace element specifies a substitution that is performed for the containing file during installation. All occurrences of the from attribute in the file are replaced with a string represented by the to and type attributes. The type attribute may have one of these values:
Usually, the from pattern is of the form @foo@, but in theory, you can replace anything because what is being done by the installer is a straightforward str_replace().
A typical use for string substitutions is setting up the PEAR install directory and PHP executable path in command-line PHP scripts. Consider this script:
#!@php_bin@ <?php print "Hello!\n"; ?>
Because the PHP executable may be installed in different locations on different machines, the PEAR installer has a configuration parameter for which PHP executable should be used (php_bin). By setting up a pear-config substitution in the package.xml file, we can insert the right path to the PHP executable during installation:
<file role="script" name="myscript"> <replace type="pear-config" from="@php_bin@" to="php_bin"/> </file>