You are here: Re: Change alternate commas to semi colons... « PHP Programming Language « IT news, forums, messages
Re: Change alternate commas to semi colons...

Posted by Andy Jeffries on 06/21/06 08:09

On Tue, 20 Jun 2006 21:41:52 +0200, Juliette wrote:
> Because he wants to change every *other* comma into a semi-colon (i.e.
> change the second, fourth etc).
> Your function would change *every* comma into a semi-colon.
>
> I don't think you can easily do it with regex as you can't really
> differentiate between comma's.

Hi Juliette,

As Rik already posted, you certainly can do it with regexes and as I
posted, they're much faster than the function call.

There's a syntax error in your script:

> for( $i=0; $i<$arraycount; $i++; ) {

should be:

> for( $i=0; $i<$arraycount; $i++ ) {

And a bug that actually gives the incorrect output. The first part of the
string from your function is:

Carson; David, Milne; Rebecca,

And it should be:

Carson, David; Milne, Rebecca;

For reference, against the larger data set from my timing post, your
function completes in 0.5357 seconds (compared to 0.8106 for Rik's
function version and 0.1960 for Rik's regex).

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация