You are here: Re: removing every even character from a string « PHP Programming Language « IT news, forums, messages
Re: removing every even character from a string

Posted by ZeldorBlat on 10/09/07 13:23

On Oct 9, 4:14 am, "Ron Barnett" <N...@Spam.Thanks> wrote:
>
> or if they are every other character , regardless of value, try:
>
> $string = '.d.fjdghdjtgkfdhfr';
> $new = '';
> for ($n = 2 to len($string)+1){
> if ($n%2==0) $new .= substr($string,$n-2,1);
>
> }
>
> this will remove all the odd characters,
> testing for $n modulus 2 ==1 will take out the even characters
>
> HTH
>
> Ron

Or, even simpler:

$new = '';
for($i = 1; $i < len($string); $i += 2)
$new .= $string[$i];

 

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

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