Phing String Manipulation

风格不统一 提交于 2019-12-23 12:42:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!