Re: Converting a string into ASCII and a bit more - newbie
| From: | Alp | Date: | Mon, 15 Nov 2004 11:44:48 +0000 |
| Subject: | Re: Converting a string into ASCII and a bit more - newbie | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202033@lists.php.net to get a copy of this message | ||
Thanks Matthew,
Got it going finally.
Would you be able to help in my further question?
Alp
"Matthew Fonda" <mfonda@dotgeek.org> wrote in message
news:1100508802.23775.0.camel@mlinux...
> This ought to work:
> <?php
> $string = 'ABCDEFGHIJ';
> $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
> for ($i = 0; $i < count($chars); $i++) {
> $chars[$i] = ord($chars[$i]);
> //$chars[$i] = ord($chars[$i]) + 10;
> }
> $string = implode('', $chars);
> ?>
>
> On Sun, 2004-11-14 at 22:32, Alp wrote:
> > Hi,
> >
> > My question could have quite stright forward answer or the question
itself
> > might be silly but being a newbie, I'll ask it anyway.
> > First I am trying to convert each character in a string into their
> > respective ASCII codes and then keep these again in a string. Such as:
> > string : ABCDEFGHIJ, expect to see in the result : 65666768697071727374
> > Then I would like to further manipulate this result with some math, say
add
> > 10 to each pair (the ascii code) so the new result becomes:
> > 75767778798081828384
> > For my first attempt I tried:
> > $x=1
> > while ($x<=strlen($string)) {
> > $holder = ord(substr($string, $x, 1));
> > $result = $result . $holder;
> > }
> > and failed since it takes ages to process and does not really return a
> > proper value/result but repetitive number such as 11111..........
> > I have also tried a 'for' example I found which failed as well.
> > I truely hope an expert here could show me some light and point me in
the
> > right direction.
> > I have 2 sets installed on my PC as PHPDEV423 and XAMPP 1.4.9 (set to
use
> > php4) and it fails in both.
> >
> > Thanks in advance,
> >
> > Alp
> > P.S.: I hope I have posted this in the correct NG
> --
> Regards,
> Matthew Fonda