Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11954 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2013-11-24 11:58 -0500 |
| Last post | 2013-11-25 03:40 +0000 |
| Articles | 17 — 10 participants |
Back to article view | Back to comp.lang.php
converting numbers to ascii values richard <noreply@example.com> - 2013-11-24 11:58 -0500
Re: converting numbers to ascii values Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-11-24 12:06 -0500
Re: converting numbers to ascii values The Natural Philosopher <tnp@invalid.invalid> - 2013-11-24 17:42 +0000
Re: converting numbers to ascii values Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-11-24 13:39 -0500
Re: converting numbers to ascii values Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-24 22:46 +0100
Re: converting numbers to ascii values Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-24 23:01 +0100
Re: converting numbers to ascii values Luuk <luuk@invalid.lan> - 2013-11-24 18:21 +0100
Re: converting numbers to ascii values richard <noreply@example.com> - 2013-11-24 13:15 -0500
Re: converting numbers to ascii values "J.O. Aho" <user@example.net> - 2013-11-24 21:53 +0100
Re: converting numbers to ascii values Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-11-25 02:50 +0000
Re: converting numbers to ascii values Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-24 22:36 -0500
Re: converting numbers to ascii values "J.O. Aho" <user@example.net> - 2013-11-25 06:47 +0100
Re: converting numbers to ascii values Luuk <luuk@invalid.lan> - 2013-11-25 13:16 +0100
Re: converting numbers to ascii values Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-11-25 02:47 +0000
Re: converting numbers to ascii values richard <noreply@example.com> - 2013-11-24 22:30 -0500
Re: converting numbers to ascii values Evan Platt <evan@theobvious.espphotography.com.invalid> - 2013-11-24 22:12 -0800
Re: converting numbers to ascii values Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-25 03:40 +0000
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-24 11:58 -0500 |
| Subject | converting numbers to ascii values |
| Message-ID | <1os8m6ou5g6i4$.1n33ilnevl0le.dlg@40tude.net> |
In BASIC I would run a for loop to print out the corresponding characters for a given value. for x=65 to 90 print chr$(x) next x would give ABCDEF...... how is this done in php?
[toc] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2013-11-24 12:06 -0500 |
| Message-ID | <Kmqku.451812$Fm2.368031@fx30.iad> |
| In reply to | #11954 |
On Sunday 24 November 2013 11:58, in comp.lang.php, "richard"
<noreply@example.com> wrote:
> In BASIC I would run a for loop to print out the corresponding characters
> for a given value.
>
> for x=65 to 90
> print chr$(x)
> next x
>
> would give ABCDEF......
>
> how is this done in php?
for ($x = 65; $x <=90; ++$x)
printf("%c",$x);
HTH
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-11-24 17:42 +0000 |
| Message-ID | <l6tdp9$2ft$1@news.albasani.net> |
| In reply to | #11955 |
On 24/11/13 17:06, Lew Pitcher wrote:
> On Sunday 24 November 2013 11:58, in comp.lang.php, "richard"
> <noreply@example.com> wrote:
>
>> In BASIC I would run a for loop to print out the corresponding characters
>> for a given value.
>>
>> for x=65 to 90
>> print chr$(x)
>> next x
>>
>> would give ABCDEF......
>>
>> how is this done in php?
>
> for ($x = 65; $x <=90; ++$x)
> printf("%c",$x);
>
>
> HTH
>
for ($x = 65; $x <91; $x++)
echo($x);
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2013-11-24 13:39 -0500 |
| Message-ID | <5Krku.401689$dn7.268916@fx20.iad> |
| In reply to | #11957 |
On Sunday 24 November 2013 12:42, in comp.lang.php, "The Natural
Philosopher" <tnp@invalid.invalid> wrote:
> On 24/11/13 17:06, Lew Pitcher wrote:
>> On Sunday 24 November 2013 11:58, in comp.lang.php, "richard"
>> <noreply@example.com> wrote:
>>
>>> In BASIC I would run a for loop to print out the corresponding
>>> characters for a given value.
>>>
>>> for x=65 to 90
>>> print chr$(x)
>>> next x
>>>
>>> would give ABCDEF......
>>>
>>> how is this done in php?
>>
>> for ($x = 65; $x <=90; ++$x)
>> printf("%c",$x);
>>
>>
>> HTH
>>
> for ($x = 65; $x <91; $x++)
> echo($x);
>
Nope. That just gets the numeric values of $x, not the ASCII (or other
characterset) equivalent.
~ $ echo '<?php for ($x = 65; $x < 91; $x++) echo($x); echo PHP_EOL ?>' |
php
6566676869707172737475767778798081828384858687888990
~ $
The alternative I suggested gives
~ $ echo '<?php for ($x = 65; $x <= 90; ++$x) printf("%c",$x);
echo PHP_EOL ?>' | php
ABCDEFGHIJKLMNOPQRSTUVWXYZ
~ $
HTH
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-24 22:46 +0100 |
| Message-ID | <20682103.Slq7mXpyxH@PointedEars.de> |
| In reply to | #11955 |
Lew Pitcher wrote:
> "richard" wrote:
>> In BASIC I would run a for loop to print out the corresponding characters
>> for a given value.
>>
>> for x=65 to 90
>> print chr$(x)
>> next x
>>
>> would give ABCDEF......
>>
>> how is this done in php?
>
> for ($x = 65; $x <=90; ++$x)
> printf("%c",$x);
There is a probably more efficient alternative to this shell-script/C like
way in PHP:
for ($i = 65; $i <= 90; ++$i)
{
echo chr($i);
}
And finally:
$ php -r 'var_dump(implode("", array_map("chr", array_keys(array_fill(65,
26, true)))));'
string(26) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-24 23:01 +0100 |
| Message-ID | <1496989.m1t3bFqGl7@PointedEars.de> |
| In reply to | #11962 |
Thomas 'PointedEars' Lahn wrote:
> Lew Pitcher wrote:
>> "richard" wrote:
>>> In BASIC I would run a for loop to print out the corresponding
>>> characters for a given value.
>>>
>>> for x=65 to 90
>>> print chr$(x)
>>> next x
>>>
>>> would give ABCDEF......
>>>
>>> how is this done in php?
>
> […]
> $ php -r 'var_dump(implode("", array_map("chr", array_keys(array_fill(65,
> 26, true)))));'
> string(26) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
That was a quick hack; this is better:
$ php -r 'var_dump(implode("", array_map("chr", range(65, 90))));'
string(26) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Note how PHP's range() differs from, e.g., Python's: <http://php.net/range>
PointedEars :)
--
When all you know is jQuery, every problem looks $(olvable).
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2013-11-24 18:21 +0100 |
| Message-ID | <76p9ma-90i.ln1@luuk.invalid.lan> |
| In reply to | #11954 |
On 24-11-2013 17:58, richard wrote: > In BASIC I would run a for loop to print out the corresponding characters > for a given value. > > for x=65 to 90 > print chr$(x) > next x > > would give ABCDEF...... > > how is this done in php? > http://us1.php.net/manual/en/function.chr.php
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-24 13:15 -0500 |
| Message-ID | <41gyawpi8u1z.ymbr00ipuiwh.dlg@40tude.net> |
| In reply to | #11956 |
On Sun, 24 Nov 2013 18:21:43 +0100, Luuk wrote: > On 24-11-2013 17:58, richard wrote: >> In BASIC I would run a for loop to print out the corresponding characters >> for a given value. >> >> for x=65 to 90 >> print chr$(x) >> next x >> >> would give ABCDEF...... >> >> how is this done in php? >> > > http://us1.php.net/manual/en/function.chr.php thanks that was what I was looking for. In my array the key is one letter. "A"=>array() "B"=>array() "C"=>array() I need to step through each character to get the list. What is a good way to do that? BASIC style x=65 while x<91 a$=chr$(x) print a$ x=x+1 wend
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-11-24 21:53 +0100 |
| Message-ID | <bff7adFecqpU1@mid.individual.net> |
| In reply to | #11959 |
On 24/11/13 19:15, richard wrote: > On Sun, 24 Nov 2013 18:21:43 +0100, Luuk wrote: > >> On 24-11-2013 17:58, richard wrote: >>> In BASIC I would run a for loop to print out the corresponding characters >>> for a given value. >>> >>> for x=65 to 90 >>> print chr$(x) >>> next x >>> >>> would give ABCDEF...... >>> >>> how is this done in php? >>> >> >> http://us1.php.net/manual/en/function.chr.php > > thanks that was what I was looking for. > In my array the key is one letter. > "A"=>array() > "B"=>array() > "C"=>array() > > I need to step through each character to get the list. > What is a good way to do that? > > BASIC style > > x=65 > while x<91 > a$=chr$(x) > print a$ > x=x+1 > wend > > for-loop works fine, you can also use foreach-loop if you have a list of keys stored in a variable. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmac_dot_com@example.com> |
|---|---|
| Date | 2013-11-25 02:50 +0000 |
| Message-ID | <XnsA282DE087171Edougmilmaccom@78.46.70.116> |
| In reply to | #11961 |
"J.O. Aho" <user@example.net> wrote in news:bff7adFecqpU1@mid.individual.net: > > for-loop works fine, you can also use foreach-loop if you have a list of > keys stored in a variable. > You don't understand. RtS isn't asking for someone to tell him how to write it -- he's asking for someone to write it for him.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-11-24 22:36 -0500 |
| Message-ID | <l6ugjq$br9$1@dont-email.me> |
| In reply to | #11967 |
On 11/24/2013 9:50 PM, Doug Miller wrote: > "J.O. Aho" <user@example.net> wrote in news:bff7adFecqpU1@mid.individual.net: > >> >> for-loop works fine, you can also use foreach-loop if you have a list of >> keys stored in a variable. >> > You don't understand. RtS isn't asking for someone to tell him how to write it -- he's asking for > someone to write it for him. > Doug, J.O. understands Richard quite well. But for others reading the newsgroup, J.O.'s update can be helpful. And I see Richard has his usual (lack of) intelligent response to you. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2013-11-25 06:47 +0100 |
| Message-ID | <bfg6j1Fk88dU1@mid.individual.net> |
| In reply to | #11969 |
On 25/11/13 04:36, Jerry Stuckle wrote: > On 11/24/2013 9:50 PM, Doug Miller wrote: >> "J.O. Aho" <user@example.net> wrote in >> news:bff7adFecqpU1@mid.individual.net: >> >>> >>> for-loop works fine, you can also use foreach-loop if you have a list of >>> keys stored in a variable. >>> >> You don't understand. RtS isn't asking for someone to tell him how to >> write it -- he's asking for >> someone to write it for him. >> > > Doug, > > J.O. understands Richard quite well. But for others reading the > newsgroup, J.O.'s update can be helpful. Thanks for replying for me, you are spot on as usually. > And I see Richard has his usual (lack of) intelligent response to you. It's his problem. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2013-11-25 13:16 +0100 |
| Message-ID | <plrbma-eq3.ln1@luuk.invalid.lan> |
| In reply to | #11959 |
On 24-11-2013 19:15, richard wrote:
> On Sun, 24 Nov 2013 18:21:43 +0100, Luuk wrote:
>
>> On 24-11-2013 17:58, richard wrote:
>>> In BASIC I would run a for loop to print out the corresponding characters
>>> for a given value.
>>>
>>> for x=65 to 90
>>> print chr$(x)
>>> next x
>>>
>>> would give ABCDEF......
no, it gives:
A
B
C
D
.....
>>>
>>> how is this done in php?
> What is a good way to do that?
>
> BASIC style
>
> x=65
> while x<91
> a$=chr$(x)
> print a$
> x=x+1
> wend
>
>
this also gives:
A
B
C
D
.....
What about trying to copy this to PHP:
$x=65;
while ($x<91) {
a$=chr($x);
print $a;
$x=$x+1;
}
RTFM:
http://us2.php.net/while
o, BTW, i left (at least) 1 error in above code,
maybe you can find it ???
;)
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmac_dot_com@example.com> |
|---|---|
| Date | 2013-11-25 02:47 +0000 |
| Message-ID | <XnsA282DD971CE9Edougmilmaccom@78.46.70.116> |
| In reply to | #11954 |
richard <noreply@example.com> wrote in news:1os8m6ou5g6i4$.1n33ilnevl0le.dlg@ 40tude.net: > In BASIC I would run a for loop to print out the corresponding characters > for a given value. > > for x=65 to 90 > print chr$(x) > next x > > would give ABCDEF...... > > how is this done in php? > http://lmgtfy.com/?q=convert+number+to+ascii+value+using+php
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-11-24 22:30 -0500 |
| Message-ID | <9bemyr871qja$.17udmixw3iifj$.dlg@40tude.net> |
| In reply to | #11966 |
On Mon, 25 Nov 2013 02:47:59 +0000 (UTC), Doug Miller wrote: > richard <noreply@example.com> wrote in news:1os8m6ou5g6i4$.1n33ilnevl0le.dlg@ > 40tude.net: > >> In BASIC I would run a for loop to print out the corresponding characters >> for a given value. >> >> for x=65 to 90 >> print chr$(x) >> next x >> >> would give ABCDEF...... >> >> how is this done in php? >> > http://lmgtfy.com/?q=convert+number+to+ascii+value+using+php http://lmgtfy.com/?q=shove+it+up+your+ass
[toc] | [prev] | [next] | [standalone]
| From | Evan Platt <evan@theobvious.espphotography.com.invalid> |
|---|---|
| Date | 2013-11-24 22:12 -0800 |
| Message-ID | <riq5999vagqgrpuf8f67gkmc9qpevogv5e@4ax.com> |
| In reply to | #11968 |
On Sun, 24 Nov 2013 22:30:38 -0500, richard <noreply@example.com> wrote: >http://lmgtfy.com/?q=shove+it+up+your+ass And you wonder why people only help you once... -- To reply via e-mail, remove The Obvious and .invalid from my e-mail address.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-11-25 03:40 +0000 |
| Message-ID | <l6ugqp$99v$1@dont-email.me> |
| In reply to | #11954 |
On Sun, 24 Nov 2013 11:58:34 -0500, richard wrote: > In BASIC I would run a for loop to print out the corresponding > characters for a given value. > > for x=65 to 90 print chr$(x) > next x > > would give ABCDEF...... > > how is this done in php? Using a combination of the following: http://php.net/manual/en/control-structures.for.php http://us3.php.net/chr http://us3.php.net/print Or in other words, just about the same way it is in basic, but using the equivalent php control structures and functions instead. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web