问题
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?
回答1:
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
回答2:
Another way to do this:
<php function="strtolower" returnProperty="paramToLower">
<param value="${param}" />
</php>
<php function="ucwords" returnProperty="paramUcwords">
<param value="${param}" />
</php>
来源:https://stackoverflow.com/questions/10432771/phing-string-manipulation