[UPHPU] Alternative ways to accomplish the same thing
Dave Smith
dave at thesmithfam.org
Tue Feb 20 15:39:38 MST 2007
Scott Hill wrote:
> Call to ItmsMaintenanceWS
> failedjavax.ejb.EJBTransactionRolledbackException:
> com.tess.common.exception.TessRuntimeException: There was an error
> validating the card. [INVALID CARD]
> at
> org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:89)
> at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
> at
> org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java
> :196)
>
> I only needed the text found in the []'s to display the error to the
> user.
I use regular expressions for this kind of stuff. That way, the pattern
you are looking for is stored declaratively instead of algorithmically
(making it much easier to read and change later). Here's how I did your
example:
$matches = array();
if( preg_match( '/\[([^\]]+)\]/', $response->faultstring, $matches ) )
{
echo $matches[1] . "\n";
}
That is admittedly a funky regular expression, because '[' and ']' are
special characters so you have to escape them to use them literally. You
might be tempted to use .* instead of the [^\]], but don't. That could
lead to funkiness because .* is greedy.
Enjoy!
--Dave
More information about the UPHPU
mailing list