我有一个使用Phing的项目,可以传递一个参数。我希望对这个参数进行简单的字符串操作,例如strtolower()或ucwords()等。你有什么想法呢?
我有一个使用Phing的项目,可以传递一个参数。我希望对这个参数进行简单的字符串操作,例如strtolower()或ucwords()等。你有什么想法呢?
可以尝试使用 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>
使用以下方式运行:
phing -Dparam=BLAH stringtest
输出:
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
构建完成
<php function="strtolower" returnProperty="paramToLower">
<param value="${param}" />
</php>
<php function="ucwords" returnProperty="paramUcwords">
<param value="${param}" />
</php>
strtolower(${param})
应该是strtolower('${param}')
(缺少 ')。你的示例将在phing stringtest -Dparam="a b.c"
上崩溃。 - ViliusL