Re: Regular expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux