php-general Digest 5 Jan 2010 13:26:27 -0000 Issue 6522
Topics (messages 300800 through 300811):
Re: What is the difference between the two streams 5.3 and 5.2 versions and
What is the need for maintaining two streams?
300800 by: viraj
300802 by: Lester Caine
300803 by: Daniel Egeberg
released: jsonDebug helper component, v1.0.0
300801 by: Rene Veerman
Luhn (modulo 10) check digit calculator
300804 by: Angus Mann
300805 by: Per Jessen
300806 by: Richard Quadling
300807 by: Richard Quadling
splitting a string
300808 by: Ingleby, Les
300809 by: Daniel Egeberg
300810 by: Ashley Sheridan
300811 by: Daniel Egeberg
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
5.3.1 is what we call 'current release'. for those who do not like to
sit on the edge, the latest is 5.2.12.
both get bug fixes (checkout the home page release announcements), so
they are 'still supported'. that means those versions earlier to
5.2.11 do not get bug fixes hence 'not supported but stable'
http://en.wikipedia.org/wiki/PHP
~viraj
On Tue, Jan 5, 2010 at 7:22 AM, Varuna Seneviratna <phpiss...@gmail.com> wrote:
> Since there are two stable versions 5.3 and 5.2 .What is the difference
> between these two streams and What is the need for maintaining two streams?
>
--- End Message ---
--- Begin Message ---
Varuna Seneviratna wrote:
Since there are two stable versions 5.3 and 5.2 .What is the difference
between these two streams and What is the need for maintaining two streams?
PHP5.3 introduced a number of 'improvements' that require many third party
packages to be re-worked. Something which has still to be completed in many
cases. In addition a number of key parts are not now available in Windows builds
of PHP5.3, so many of us do not have the option as yet to switch TO the 5.3
branch in production. Until PHP5.3 is fully supported and complete, 5.2 still
needs to be maintained!
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
--- End Message ---
--- Begin Message ---
On Tue, Jan 5, 2010 at 10:34, Daniel Egeberg <degeb...@php.net> wrote:
> On Tue, Jan 5, 2010 at 02:22, Varuna Seneviratna <phpiss...@gmail.com> wrote:
>> Since there are two stable versions 5.3 and 5.2 .What is the difference
>> between these two streams and What is the need for maintaining two streams?
>
> The PHP 5.3.x branch is still pretty new. That is why 5.2.x is still
> maintained to provide bug fixes and security patches seeing as there
> are still a lot of people using that branch.
>
> If you are going to do a new install, PHP 5.3.1 should be just fine for you.
And that was supposed to have gone to the list as well. Sorry. Hit the
wrong button.
--
Daniel Egeberg
--- End Message ---
--- Begin Message ---
I was dealing with large & deep arrays in PHP and wanted a better way to
view such data structures in the browser.
So i've built a few functions that show such structures initially collapsed,
with various options to click-and-see what's in a sub-value.
It can also handle HTML within JSON, and JSON within JSON.
Dumping an array from PHP is as simple as
htmlDump ($arr, $title);
For a demo & download (LGPL) see http://skatescene.biz/jsonDebug-1.0.0/
If you have any improvements, please let me know; rene7...@gmail.com
--- End Message ---
--- Begin Message ---
Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code to
calculate a Luhn check-digit?
It's a check-digit often added to the end of things like credit card or account
numbers to make detecting typo's a bit easier.
I found lots of code to validate a number once the check-digit is applied, but
nothing to calculate the digit in the first place.
Thanks in advance !
Angus
--- End Message ---
--- Begin Message ---
Angus Mann wrote:
> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste
> code to calculate a Luhn check-digit?
>
http://de.wikipedia.org/wiki/Luhn-Algorithmus
(several examples, including one in PHP).
/Per
--
Per Jessen, Zürich (0.0°C)
--- End Message ---
--- Begin Message ---
2010/1/5 Angus Mann <angusm...@pobox.com>:
> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code
> to calculate a Luhn check-digit?
>
> It's a check-digit often added to the end of things like credit card or
> account numbers to make detecting typo's a bit easier.
>
> I found lots of code to validate a number once the check-digit is applied,
> but nothing to calculate the digit in the first place.
>
> Thanks in advance !
> Angus
>
>
Modified version found at
http://blog.planzero.org/2009/08/luhn-modulus-implementation-php/
<?php
/* Luhn algorithm number checker - (c) 2005-2008 - planzero.org *
* This code has been released into the public domain, however please *
* give credit to the original author where possible. */
function luhn_check($number) {
// If the total mod 10 equals 0, the number is valid
return (luhn_process($number) % 10 == 0) ? TRUE : FALSE;
}
function luhn_process($number) {
// Strip any non-digits (useful for credit card numbers with spaces
and hyphens)
$number=preg_replace('/\D/', '', $number);
// Set the string length and parity
$number_length=strlen($number);
$parity=$number_length % 2;
// Loop through each digit and do the maths
$total=0;
for ($i=0; $i<$number_length; $i++) {
$digit=$number[$i];
// Multiply alternate digits by two
if ($i % 2 == $parity) {
$digit*=2;
// If the sum is two digits, add them together (in effect)
if ($digit > 9) {
$digit-=9;
}
}
// Total up the digits
$total+=$digit;
}
return $total;
}
function luhn_checkdigit($number) {
return 10 - (luhn_process($number . '0') % 20);
}
echo '49927398716 is ', (luhn_check('49927398716') ? 'Valid' :
'Invalid'), PHP_EOL;
echo 'The check digit for 4992739871 is ',
luhn_checkdigit('4992739871'), PHP_EOL;
?>
outputs ...
49927398716 is Valid
The check digit for 4992739871 is 6
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
2010/1/5 Richard Quadling <rquadl...@googlemail.com>:
> 2010/1/5 Angus Mann <angusm...@pobox.com>:
>> Hi all. Perhaps a lazy request, but does anybody have some cut-n-paste code
>> to calculate a Luhn check-digit?
>>
>> It's a check-digit often added to the end of things like credit card or
>> account numbers to make detecting typo's a bit easier.
>>
>> I found lots of code to validate a number once the check-digit is applied,
>> but nothing to calculate the digit in the first place.
>>
>> Thanks in advance !
>> Angus
>>
>>
>
> Modified version found at
> http://blog.planzero.org/2009/08/luhn-modulus-implementation-php/
>
> <?php
> /* Luhn algorithm number checker - (c) 2005-2008 - planzero.org *
> * This code has been released into the public domain, however please *
> * give credit to the original author where possible. */
>
> function luhn_check($number) {
> // If the total mod 10 equals 0, the number is valid
> return (luhn_process($number) % 10 == 0) ? TRUE : FALSE;
>
> }
>
> function luhn_process($number) {
>
> // Strip any non-digits (useful for credit card numbers with spaces
> and hyphens)
> $number=preg_replace('/\D/', '', $number);
>
> // Set the string length and parity
> $number_length=strlen($number);
> $parity=$number_length % 2;
>
> // Loop through each digit and do the maths
> $total=0;
> for ($i=0; $i<$number_length; $i++) {
> $digit=$number[$i];
> // Multiply alternate digits by two
> if ($i % 2 == $parity) {
> $digit*=2;
> // If the sum is two digits, add them together (in effect)
> if ($digit > 9) {
> $digit-=9;
> }
> }
> // Total up the digits
> $total+=$digit;
> }
>
> return $total;
> }
>
> function luhn_checkdigit($number) {
> return 10 - (luhn_process($number . '0') % 20);
> }
>
>
> echo '49927398716 is ', (luhn_check('49927398716') ? 'Valid' :
> 'Invalid'), PHP_EOL;
> echo 'The check digit for 4992739871 is ',
> luhn_checkdigit('4992739871'), PHP_EOL;
> ?>
>
>
> outputs ...
>
> 49927398716 is Valid
> The check digit for 4992739871 is 6
>
>
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>
And that 20 is a typo. Sorry.
function luhn_checkdigit($number) {
return 10 - (luhn_process($number . '0') % 10);
}
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
Hi all, first time I have posted here so please be nice.
I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to do
is to take the file name which is output using the getProp() function and then
remove the file extension from the end of the file for example:
Original name held in the getProp() array [name] "word_doccument.docx"
I need to put this into a string such as
$filename = $props['name'];
I then need to separate the file name from the file extension.
I have been reading the php manual do please don't bother referring me to that.
Thanks in advance.
LEGAL INFORMATION
Information contained in this e-mail may be subject to public disclosure under
the Freedom of Information Act 2000. Unless the information is legally exempt,
the confidentiality of this e-mail and your reply cannot be guaranteed.
Unless expressly stated otherwise, the information contained in this e-mail &
any files transmitted with it are intended for the recipient only. If you are
not the intended recipient you must not copy, distribute, or take any action or
reliance upon it. If you have received this e-mail in error, you should notify
the sender immediately and delete this email. Any unauthorised disclosure of
the information contained in this e-mail is strictly prohibited. Any views or
opinions presented are solely those of the author and do not necessarily
represent those of Tyne Metropolitan College unless explicitly stated otherwise.
This e-mail and attachments have been scanned for viruses prior to leaving Tyne
Metropolitan College. Tyne Metropolitan College will not be liable for any
losses as a result of any viruses being passed on.
--- End Message ---
--- Begin Message ---
On Tue, Jan 5, 2010 at 13:39, Ingleby, Les <les.in...@tynemet.ac.uk> wrote:
> Hi all, first time I have posted here so please be nice.
>
> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to
> do is to take the file name which is output using the getProp() function and
> then remove the file extension from the end of the file for example:
>
> Original name held in the getProp() array [name] "word_doccument.docx"
>
> I need to put this into a string such as
>
> $filename = $props['name'];
>
> I then need to separate the file name from the file extension.
>
> I have been reading the php manual do please don't bother referring me to
> that.
>
> Thanks in advance.
There are a couple of ways you could do this. The most straightforward
way would be to use the pathinfo() function.
<?php
$file = 'word_document.docx';
$extension = pathinfo($file, PATHINFO_EXTENSION);
$name = pathinfo($file, PATHINFO_FILENAME);
?>
See http://php.net/pathinfo for more information about that function.
You could also explode() it and do something with that, or you could
or use some of the other many string manipulation functions. I think
pathinfo() is easiest.
--
Daniel Egeberg
--- End Message ---
--- Begin Message ---
On Tue, 2010-01-05 at 12:39 +0000, Ingleby, Les wrote:
> Hi all, first time I have posted here so please be nice.
>
> I am using PEAR HTTP_Upload to handle multiple file uploads. What I need to
> do is to take the file name which is output using the getProp() function and
> then remove the file extension from the end of the file for example:
>
> Original name held in the getProp() array [name] "word_doccument.docx"
>
> I need to put this into a string such as
>
> $filename = $props['name'];
>
> I then need to separate the file name from the file extension.
>
> I have been reading the php manual do please don't bother referring me to
> that.
>
> Thanks in advance.
>
> LEGAL INFORMATION
> Information contained in this e-mail may be subject to public disclosure
> under the Freedom of Information Act 2000. Unless the information is legally
> exempt, the confidentiality of this e-mail and your reply cannot be
> guaranteed.
> Unless expressly stated otherwise, the information contained in this e-mail &
> any files transmitted with it are intended for the recipient only. If you are
> not the intended recipient you must not copy, distribute, or take any action
> or reliance upon it. If you have received this e-mail in error, you should
> notify the sender immediately and delete this email. Any unauthorised
> disclosure of the information contained in this e-mail is strictly
> prohibited. Any views or opinions presented are solely those of the author
> and do not necessarily represent those of Tyne Metropolitan College unless
> explicitly stated otherwise.
> This e-mail and attachments have been scanned for viruses prior to leaving
> Tyne Metropolitan College. Tyne Metropolitan College will not be liable for
> any losses as a result of any viruses being passed on.
PHPBB uses the substr() function along with the strrpos() function to
grab the extension from a file. You could do something like this:
(untested - I always forget the order of the params!)
$name = substr($filename, 0, strrpos($filename, '.'));
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Tue, Jan 5, 2010 at 14:13, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> (untested - I always forget the order of the params!)
As a general rule, string functions are always haystack-needle and
array functions are always needle-haystack. I can't think of any
exceptions to that rule.
--
Daniel Egeberg
--- End Message ---