php-general Digest 1 Nov 2008 13:05:02 -0000 Issue 5767
Topics (messages 282733 through 282736):
Re: Bitwise operation giving wrong results
282733 by: sean greenslade
Re: Count the Number of Elements Using Explode
282734 by: Lars Torben Wilson
Re: Reg Ex
282735 by: Ashley Sheridan
Control Over Printer Queue On Windows
282736 by: shahrzad khorrami
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
---------- Forwarded message ----------
From: sean greenslade <[EMAIL PROTECTED]>
Date: Fri, Oct 31, 2008 at 11:22 PM
Subject: Re: [PHP] Bitwise operation giving wrong results
To: Yeti <[EMAIL PROTECTED]>
Cool, thanks. It worked. I didn't know you typeset PHP like that.
On Thu, Oct 30, 2008 at 3:42 AM, Yeti <[EMAIL PROTECTED]> wrote:
> Usually in PHP one does not take much care about the data types, but
> in this case you absoloodle have to.
> If you use bit operators on a character then its ascii number will be
> taken instead (how should a number based operation work with a
> string?)
>
> also if you pass on $_GET params directly into ay bitwise operation
> you might get some un-nice behaviour. So check them first.
>
> <?php
> $a = $b = false;
> if (is_numeric($_GET['b'].$_GET['a'])) {
> $a = (int)$_GET['a'];
> $b = (int)$_GET['b'];
> echo $a & $b;
> }
> ?>
>
--
--Zootboy
--
--Zootboy
--- End Message ---
--- Begin Message ---
2008/10/31 Stut <[EMAIL PROTECTED]>:
> On 31 Oct 2008, at 17:32, Maciek Sokolewicz wrote:
>>
>> Kyle Terry wrote:
>>>
>>> ---------- Forwarded message ----------
>>> From: Kyle Terry <[EMAIL PROTECTED]>
>>> Date: Fri, Oct 31, 2008 at 9:31 AM
>>> Subject: Re: [PHP] Count the Number of Elements Using Explode
>>> To: Alice Wei <[EMAIL PROTECTED]>
>>> I would use http://us2.php.net/manual/en/function.array-count-values.php
>>> On Fri, Oct 31, 2008 at 9:29 AM, Alice Wei <[EMAIL PROTECTED]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have a code snippet here as follows:
>>>>
>>>> $message="1|2|3|4|5";
>>>> $stringChunks = explode("|", $message);
>>>>
>>>> Is it possible to find out the number of elements in this string? It
>>>> seems
>>>> that I could do things like print_r and find out what is the last
>>>> element of
>>>> $stringChunks is, but is there a way where I can use code from the two
>>>> lines
>>>> and have it print out 5 as the number of elements that contains after
>>>> the
>>>> splitting?
>>>>
>>>> Or, am I on the wrong direction here?
>>>>
>>>> Thanks in advance.
>>>>
>>>> Alice
>>
>> First of all, don't top post, please.
>> Secondly, that won't do what the OP asked for. array_count_values returns
>> an array which tells you how often each VALUE was found in that array. so:
>> array_count_values(array(1,2,3,4,5)) will return:
>> array(1=>1,2=>1,3=>1,4=>1,5=>1). While what the OP wanted was:
>> some_function(array(1,2,3,4,5)) to return 5 (as in the amount of values, not
>> how often each value was found in the array).
>> count() would do it directly, and the other suggestions people gave do it
>> indirectly, assuming that the values between '|' are never > 1 char wide.
>
> I think you'll find Kyle was suggesting that the OP use that function to
> count the |'s in the string. Add 1 to that and you have the number of
> elements explode will produce. More efficient if you're simply exploding it
> to count the elements, but count would be better if you need to explode them
> too.
>
> -Stut
For the case where you want to explode a string and afterwards count
the number of elements you wind up with, Maciek is right: count() is
the correct function to use. array_count_values() will not work on the
original string and after exploding will have no
useful effect on the resulting string as far as counting the number of
separators goes.
If you don't actually need to explode the string but just want to
count the separators, you could use some weird logic to get
array_count_values() to count the number of times '|' appeared in the
original string--but it would be pointless. count_chars() would be a
much better choice for what you are suggesting.
Torben
--- End Message ---
--- Begin Message ---
On Fri, 2008-10-31 at 15:03 +0100, Jochem Maas wrote:
> Eric Butera schreef:
> > On Fri, Oct 31, 2008 at 9:09 AM, Warren Windvogel
> > <[EMAIL PROTECTED]> wrote:
> >> Eric Butera wrote:
> >>> Who says every file will have an extension? Who says they're all .+3
> >>> chars? When I first started php I tried that and it failed in a lot
> >>> of places.
> >> I've also run into that problem in the past. The way that I could work
> >> around all these issues was to document naming conventions for the files
> >> and
> >> validate these before using the regex to obtain the necessary information.
> >>
> >> Regards
> >> Warren
> >>
> >
> > ...or you could just use pathinfo and be done with it. I work for
> > clients. Clients shouldn't have to read a faq to upload a file.
>
> no. they generally believe that when they upload a CSV file in a field
> very clearly marked "upload your FLASH file here" things should just work :-)
>
> >
>
>
I had exactly the same problem with someone wondering why a PDF CV
wouldnt upload in a form marked CSV upload, she adamantly refused to
read it properly!
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Hi all,
I am writing a script to print a few thousand pdf documents and I need
to have some control over the number of jobs that are sent to the
printer queue at time ...
I can not see how to get print queue information eg the number of
jobs pending .. at least my attempts are failing..
any ideas?
Thanks in advance
--- End Message ---