Re[6]: preg_replace: avoiding double replacements

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

 



Ash,

Actually it's not the Caesar cypher itself (see
http://en.wikipedia.org/wiki/Temurah_(Kabbalah), third method), but
your way of transformation seems to me the best for a while)
                                                            Thanks!

-- 
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
To: Peter Lind <peter.e.lind@xxxxxxxxx>
Date: Tuesday, May 18, 2010, 2:32:11 PM
Subject:  preg_replace: avoiding double replacements

On Tue, 2010-05-18 at 13:09 +0200, Peter Lind wrote:

> On 18 May 2010 12:35, Andre Polykanine <andre@xxxxxxxx> wrote:
> > Hello Peter,
> >
> > Hm... I see I need to specify what I'm really doing. Actually, I need
> > to change the letters in the text. It's a famous and ancient crypting
> > method: you divide the alphabet making two parts, then you change the
> > letters of one part with letters for other part (so A becomes N, B
> > becomes O, etc., and vice versa). it works fine and slightly with
> > strtr or str_replace... but only if the text is not in utf-8 and it
> > doesn't contain any non-English letters such as Cyrillic what I need.
> > What my regex does is the following: it sees an A, well it changes it
> > to N; then it goes through the string and sees an N... what does it
> > do? Surely, it changes it back to A! I hoped (in vain) that there
> > exists a modifier preventing this behavior... but it seems that it's
> > false(
> > Thanks!
> 
> Hmmm, what comes to mind is using your string as an array and
> translating one character after another, building your output string
> using a lookup table. Not entirely sure how that will play with utf8
> characters, you'd have to try and see.
>  I don't think you'll get any of PHPs string functions to do the work
> for you - they'll do the job in serial, not parallel.
> 
> Regards
> Peter
> 
> -- 
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> Flickr: http://www.flickr.com/photos/fake51
> BeWelcome: Fake51
> Couchsurfing: Fake51
> </hype>
> 


If you're wanting to use the Caesar cypher (for that's what it is) then
why not just modify the entire string, character by character, to use a
character code n characters ahead. For example, a capital A is ascii 65,
you want to change it to an N to add 14 to that. Just keep n the same
throughout and it's easy to convert back.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
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