You are here: RE: [PHP] Detecting case change? « PHP « IT news, forums, messages
RE: [PHP] Detecting case change?

Posted by David Yee on 07/22/05 01:48

That'll work- didn't realize you can compare strings like that in PHP-
thanks guys.

David

-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: Thursday, July 21, 2005 3:38 PM
To: Philip Hallstrom
Cc: David Yee; PHP-General
Subject: Re: [PHP] Detecting case change?


On Thu, 2005-07-21 at 18:30, Philip Hallstrom wrote:
> > Hi- how can I find the character postion in a string right before the
first
> > case change? Is there a function out there that already does this?
E.g.
> > passing the string "WebApplication" to this function would return the
number
> > 2. Thanks for any input.
>
> I can't think of a function that does this, but something like this
> should work. Not sure how efficient it is to constantly call substr()
> on the string. Might be better to split it up into an array to start
> with. Or there might be a "get character at" function, but I don't see
> it right now...
>
> $word = "WebApplication";
> $length = strlen($word);
>
> for ( $i = 1; $i < $length; $i++ ) {
> $a = substr($word, $i - 1, 1);
> $b = substr($word, $i, 1);

Just in case you're not aware... you can loop over a strings characters
using the string index notation:

$length = strlen( $word );
for( $i = 1; $i < $lengthl $i++ )
{
$a = $word{$i - 1};
$b = $word{$i};
}

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

 

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

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