Re: Regular expression

From: Date: Mon, 30 Jan 2006 14:46:52 +0000
Subject: Re: Regular expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-229470@lists.php.net to get a copy of this message
Barry wrote:
Simple reg help please i want to match the last "," in "a,b,c,d" and replace it with " and "
Without using a regexp, you could do: <code> $string = 'a,b,c,d'; $letters = explode(',', $string); $last_letter = array_pop($letters); $final_string = implode(',', $letters) . ' and ' . $last_letter; </code> Not very efficient - but should work... Silvio -- tradeOver | http://www.tradeover.net ...ready to become the King of the World?

« previous php.general (#229470) next »