CHAPTER 12 – 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 con- figuration data in sync with the user's PEAR configuration, to invoke PHP with the right PATH, and more.
Element: <replace> Element name: replace Attributes: from (required) to (required) type (required) May occur in: file (optional) 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: php-const. from is replaced by the value of the PHP constant named by to. pear-config. from is replaced by the PEAR configuration parameter named by to. package-info. from is replaced by the to field from the package's configuration. 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 straightfor- ward str_replace().
Examples 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>