Search code examples
phing

Phing String Manipulation


I have a Phing project that you pass in a parameter. I want to perform simple string manipulation on this parameter such a strtolower() or ucwords() etc. Any ideas how I can go about this?


Solution

  • How about using the PhpEvaLTask:

    <project name="StringTest" default="all" basedir=".">
    <target name="stringtest"  description="test">
        <php expression="strtolower(${param})" returnProperty="paramToLower"/>
        <php expression="ucwords(${param})" returnProperty="paramUcwords"/>
        <echo>To lower ${paramToLower}</echo>
        <echo>UcWords ${paramUcwords}</echo>
    </target>
    

    Running it with:

    phing -Dparam=BLAH stringtest
    

    Yields:

    Buildfile: /export/users/marcelog/build.xml
    

    StringTest > stringtest:

      [php] Evaluating PHP expression: strtolower(BLAH)
      [php] Evaluating PHP expression: ucwords(BLAH)
     [echo] To lower blah
     [echo] UcWords BLAH
    

    BUILD FINISHED