Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phing String Manipulation

Tags:

phing

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?

like image 513
Gabe Avatar asked Dec 10 '22 00:12

Gabe


2 Answers

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

like image 93
marcelog Avatar answered Dec 31 '22 06:12

marcelog


Another way to do this:

<php function="strtolower" returnProperty="paramToLower">
    <param value="${param}" />
</php>

<php function="ucwords" returnProperty="paramUcwords">
    <param value="${param}" />
</php>
like image 44
Marek Vantuch Avatar answered Dec 31 '22 06:12

Marek Vantuch