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 Ron Barnett on 10/09/07 08:14

"yawnmoth" <terra1024@yahoo.com> wrote in message
news:1191910497.284515.252710@50g2000hsm.googlegroups.com...
> Say I had .a.b.c and wanted to return abc. Any ideas as to how I'd do
> this? Here's my attempt, but it doesn't work:
>
> <?php
> echo preg_replace('#(?:.(.))+#s', '$1', '.a.b.c');
> ?>
>
> Any ideas?

Hi, If you know that the characters are dots, just str_replace them with
nothing

$new = str_replace('.','','.a.b.c');

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

 

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

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