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?
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
Another way to do this:
<php function="strtolower" returnProperty="paramToLower">
<param value="${param}" />
</php>
<php function="ucwords" returnProperty="paramUcwords">
<param value="${param}" />
</php>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With