php-general Digest 14 Dec 2010 10:50:58 -0000 Issue 7086
php-general Digest 14 Dec 2010 10:50:58 - Issue 7086 Topics (messages 310007 through 310021): Re: array_multisort into Natural order? 310007 by: Jim Lucas 310008 by: George Langley 310021 by: Richard Quadling Re: Use PHP the way God intended... 310009 by: Daevid Vincent 310016 by: Robert Cummings 310017 by: Paul M Foster 310020 by: David Harkness Re: empty() in email message 310010 by: Andre Polykanine 310011 by: Daevid Vincent 310013 by: Gary 310014 by: Gary 310015 by: Gary 310018 by: Gary 310019 by: Gary Re: Scalable Vector Graphics with PHP 310012 by: sudarshana sampath 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 -- ---BeginMessage--- On 12/13/2010 11:59 AM, George Langley wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc. But using array_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc. Anyone have a solution to this limitation already? Nothing found in the archives or Googling. Thanks. assuming that you are not using other options of array_multisort(), why not do something like this. $ar = array_merge($array1, $array2, $array3); natsort($ar); George LangleyMultimedia DeveloperAudio/Video EditorMusician, Arranger, Composer www.georgelangley.ca ---End Message--- ---BeginMessage--- Hi there! Correct me if I'm wrong but merge() just makes one array of all items. array_multisort() keeps each array separate, while applying the same re-ordering to all three arrays. This allows you to use the same position number to get the required elements from each array, especially where each array is a list of different properties. For example: $name = array(Joe, Charlie, Jack); $age = array(30, 12, 66); $job = array(Plumber, Student, Retired); array_multisort($name, $age, $job); // will re-order all three arrays based on a regular alphanumeric sort of the names: // $name is now array(Charlie, Jack, Joe); // $age is now array(12, 66, 30); // $job is now array(Student, Retired, Plumber, ); // can now do: $firstName = $name[0]; // returns Charlie $firstAge = $age[0]; // returns Charlie's age 12 $firstJob = $job[0]; // returns Charlie's job Student A merge of these arrays will lose the different types of info each array currently has, and make it impossible to match a name to the age or job. Now, my other option is to group the items into a set of arrays: $array1 = array('name' = 'Joe', age = '30' job = 'Plumber'); $array2 = array('name' = 'Charlie', age = '12' job = 'Student'); $array3 = array('name' = 'Jack', age = '66' job = 'Retired'); $largeArray = array($array1, $array2, $array3); But, is there a way to the sort $largeArray, based on the name value in each individual array? And if so, can that use the natsort()? I don't think an asort() can do either. Note that the original source of this info is a mySQL db call, and it is initially sorted in the query, but again, there doesn't appear to be a way to natural sort an SQL query either. So I get file1, file10, file2, file20, file5 instead of file1, file2, file5, file10, file20 G - Original Message - From: Jim Lucas li...@cmsws.com Date: Monday, December 13, 2010 16:00 Subject: Re: [PHP] array_multisort into Natural order? To: George Langley george.lang...@shaw.ca Cc: php-gene...@lists.php.net On 12/13/2010 11:59 AM, George Langley wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc. But using array_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc. Anyone have a solution to this limitation already? Nothing found in the archives or Googling. Thanks. assuming that you are not using other options of array_multisort(), why not do something like this. $ar = array_merge($array1, $array2, $array3); natsort($ar); George Langley Multimedia Developer Audio/Video Editor Musician, Arranger, Composer www.georgelangley.ca George Langley Multimedia Developer Audio/Video Editor Musician, Arranger, Composer www.georgelangley.ca ---End Message--- ---BeginMessage--- On 13 December 2010 19:59, George Langley george.lang...@shaw.ca wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order -
php-general Digest 14 Dec 2010 23:45:51 -0000 Issue 7087
php-general Digest 14 Dec 2010 23:45:51 - Issue 7087 Topics (messages 310022 through 310038): Re: array_multisort into Natural order? 310022 by: Richard Quadling Re: good, popular? 310023 by: Sam Smith 310026 by: Nathan Rixham 310027 by: David Hutto 310029 by: David Hutto 310030 by: Richard Quadling 310032 by: Richard Quadling 310033 by: larry.garfieldtech.com 310034 by: Adam Richardson 310037 by: Lester Caine 310038 by: Govinda Re: Use PHP the way God intended... 310024 by: Jay Blanchard 310025 by: Robert Cummings 310028 by: Daniel Brown 310031 by: Paul M Foster 310035 by: David Harkness 310036 by: Daniel Brown 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 -- ---BeginMessage--- On 14 December 2010 10:50, Richard Quadling rquadl...@gmail.com wrote: On 13 December 2010 19:59, George Langley george.lang...@shaw.ca wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc. But using array_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc. Anyone have a solution to this limitation already? Nothing found in the archives or Googling. Thanks. George Langley Multimedia Developer Audio/Video Editor Musician, Arranger, Composer www.georgelangley.ca Based upon code I found at [1] I have the following function [2] which I use to sort result sets. I've just added natural sorting (and natural caseless sorting) and some examples on usage. It might be slightly over the top, but it works well for me. No need to extract the columns from the rows to supply to the sorter. If you like it and find any issues with it, or enhancements, then I'd be grateful if you could pass them back to me. Richard. [1] http://www.php.net/manual/en/function.array-multisort.php#68452 [2] http://pastebin.com/8JsMX7yS The function uses a closure for the sorting. If you are on PHP 5.3.0, then you'll have to extract the function into a normal one and add ... global $a_AMCOrdering; to each function. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY ---End Message--- ---BeginMessage--- Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? Thanks ---End Message--- ---BeginMessage--- Sam Smith wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? It's probably you're best bet, and is certainly good :) failing that just generic db specific functions or some form of framework to wrap it all up, like doctrine or some such. Would recommend PDO as a nice abstraction layer though that's well used/tested. Best, Nathan ---End Message--- ---BeginMessage--- On Tue, Dec 14, 2010 at 6:10 AM, Sam Smith a...@itab.com wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? In previous experience with questions such as these, you will get several types of individual responses to usages of the software. Some good, some bad, depending on the experience level of the commenter with both the language and the code in question. It's a combination of your current understanding of php and the associated usages of other languages, and what you want to know. Don't trust what people say, trust what feels right at the current time of your usage of the php library available/your experience level, and what you currently know how to use. From my experience with several languages, once you know the basics, even if you do re-invent the 'wheel', so did firestone,michelin, and goodyear, and they're not complaining. And you'll feel better for reinventing, than using someone elses. Thanks ---End Message--- ---BeginMessage--- In other words, in ten years from now, even the advisors you get today will rethink their answers with 20/20/hindsight, and not think about your ignorance of technology, but their own. ---End Message--- ---BeginMessage--- On 14 December 2010 11:10, Sam Smith a...@itab.com wrote: Searching for PHP CRUD in hopes of learning the best way
Re: [PHP] array_multisort into Natural order?
On 13 December 2010 19:59, George Langley george.lang...@shaw.ca wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc. But using array_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc. Anyone have a solution to this limitation already? Nothing found in the archives or Googling. Thanks. George Langley Multimedia Developer Audio/Video Editor Musician, Arranger, Composer www.georgelangley.ca Based upon code I found at [1] I have the following function [2] which I use to sort result sets. I've just added natural sorting (and natural caseless sorting) and some examples on usage. It might be slightly over the top, but it works well for me. No need to extract the columns from the rows to supply to the sorter. If you like it and find any issues with it, or enhancements, then I'd be grateful if you could pass them back to me. Richard. [1] http://www.php.net/manual/en/function.array-multisort.php#68452 [2] http://pastebin.com/8JsMX7yS -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array_multisort into Natural order?
On 14 December 2010 10:50, Richard Quadling rquadl...@gmail.com wrote: On 13 December 2010 19:59, George Langley george.lang...@shaw.ca wrote: Hi all. Can use natsort($array1) to sort a single array of filenames into a natural alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc. But using array_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up with 1.php, 10.php, 2.php, 20.php, 5.php, etc. Anyone have a solution to this limitation already? Nothing found in the archives or Googling. Thanks. George Langley Multimedia Developer Audio/Video Editor Musician, Arranger, Composer www.georgelangley.ca Based upon code I found at [1] I have the following function [2] which I use to sort result sets. I've just added natural sorting (and natural caseless sorting) and some examples on usage. It might be slightly over the top, but it works well for me. No need to extract the columns from the rows to supply to the sorter. If you like it and find any issues with it, or enhancements, then I'd be grateful if you could pass them back to me. Richard. [1] http://www.php.net/manual/en/function.array-multisort.php#68452 [2] http://pastebin.com/8JsMX7yS The function uses a closure for the sorting. If you are on PHP 5.3.0, then you'll have to extract the function into a normal one and add ... global $a_AMCOrdering; to each function. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PDO: good, popular?
Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? Thanks
RE: [PHP] Use PHP the way God intended...
[snip] Nah, if he'd read it backwards, you'd be able to hear MePHPistoPHPeles say, Rasmus is the Penguin. (Yes, you have to be dang old to get that obscure reference. ;-) Pshaw, not *that* old! I get the reference, and I'm only . . . oh, damn. :( [/snip] Uhhyeah -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On Tue, Dec 14, 2010 at 6:10 AM, Sam Smith a...@itab.com wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? In previous experience with questions such as these, you will get several types of individual responses to usages of the software. Some good, some bad, depending on the experience level of the commenter with both the language and the code in question. It's a combination of your current understanding of php and the associated usages of other languages, and what you want to know. Don't trust what people say, trust what feels right at the current time of your usage of the php library available/your experience level, and what you currently know how to use. From my experience with several languages, once you know the basics, even if you do re-invent the 'wheel', so did firestone,michelin, and goodyear, and they're not complaining. And you'll feel better for reinventing, than using someone elses. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Use PHP the way God intended...
On Tue, Dec 14, 2010 at 09:29, Robert Cummings rob...@interjinn.com wrote: I must have been under a rock when the reference came out :| Or you may have still been in shock from hearing that Paul was dead. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On 14 December 2010 11:10, Sam Smith a...@itab.com wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? Thanks If you are developing code for a single database and you are really, really sure you're not going to ever use another DB, then maybe PDO is an unnecessary layer. If you are developing code which has to remain compatible across multiple DBs, then PDO would, on the surface, seem like a good idea. The downside though is that PDO still requires DB specific drivers. I only work on 1 DB (MS SQL). So, I don't use PDO. From http://docs.php.net/manual/en/intro.pdo.php : PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
In other words, in ten years from now, even the advisors you get today will rethink their answers with 20/20/hindsight, and not think about your ignorance of technology, but their own. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Use PHP the way God intended...
On Tue, Dec 14, 2010 at 11:15:59AM -0500, Daniel Brown wrote: On Tue, Dec 14, 2010 at 09:29, Robert Cummings rob...@interjinn.com wrote: I must have been under a rock when the reference came out :| Or you may have still been in shock from hearing that Paul was dead. Er... that's Paul McCartney, not Paul Foster. Whew! Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On 14 December 2010 15:45, David Hutto smokefl...@gmail.com wrote: From my experience with several languages, once you know the basics, even if you do re-invent the 'wheel', so did firestone,michelin, and goodyear, and they're not complaining. And you'll feel better for reinventing, than using someone elses. Strange that you should mention those tyre manufacturers. I work for a tyre remoulder. We take their dead tyres and remake them into high quality remoulds. The majority of all food delivered in the UK run on our tyres! Essentially, we are recycling. Looking to the future and all that. If you can recycle others code into new and interesting ways, then go for it. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
I'm the DB maintainer for Drupal 7, and we rebuilt our entire DB layer on top of PDO. It's a rather nice API, although as others have noted it does not abstract away SQL entirely; it abstracts the API calls you need to use to get to SQL. We then built a layer on top of that which does abstract away most database weirdness using fluent query builders. It's much lighter-weight than an ORM. I'm in the process of spinning it off as a stand-alone library because we think it's that cool, but it's not completely divorced from Drupal yet. Stay tuned. :-) But yes, PDO is nice. --Larry Garfield On 12/14/10 5:10 AM, Sam Smith wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On Tue, Dec 14, 2010 at 6:10 AM, Sam Smith a...@itab.com wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? Thanks I like working with PDO. I use a very thin set of wrapper functions to automatically grab the connection information from a config file, cause errors to be thrown as exceptions, and make sure the results are formatted as arrays. It works very well and relatively fast. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
Re: [PHP] Use PHP the way God intended...
On Tue, Dec 14, 2010 at 8:43 AM, Paul M Foster pa...@quillandmouse.comwrote: Er... that's Paul McCartney, not Paul Foster. Whew! Paul McCartney's dead?? But the Beatles just released a ton of albums on iTunes! So sad...
Re: [PHP] Use PHP the way God intended...
On Tue, Dec 14, 2010 at 11:43, Paul M Foster pa...@quillandmouse.com wrote: Er... that's Paul McCartney, not Paul Foster. Whew! HA! Sorry to make your heart jump. ;-P -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
la...@garfieldtech.com wrote: I'm the DB maintainer for Drupal 7, and we rebuilt our entire DB layer on top of PDO. It's a rather nice API, although as others have noted it does not abstract away SQL entirely; it abstracts the API calls you need to use to get to SQL. We then built a layer on top of that which does abstract away most database weirdness using fluent query builders. It's much lighter-weight than an ORM. I'm in the process of spinning it off as a stand-alone library because we think it's that cool, but it's not completely divorced from Drupal yet. Stay tuned. :-) Larry - how many databases does it actually work with? Having rebuilt the DB layer using PDO did you actually gain anything? Sam - The situation on database abstraction is not clear cut and a lot of tangents have been generated while the traditional approaches are still the best in many cases. As has been said ... if you only intend to use on database, then use the matching driver and work the SQL in a manor that works for you with that database. If you need a full range of databases supported, then ADOdb is STILL the best option, and will quite happily use a PDO or generic driver internally depending on your choice, but which ever you use ( and the generic ones still tend to be faster especially with the accelerator package ) the abstraction of the SQL is much more important then simply managing a few data conversions. ADOdb will build tables across the whole range of databases it supports from a single 'profile', while PDO needs a lot of help to do the same, preferring instead to have separate 'profiles' for each database each hand coded. PDO still needs a number of areas finishing before it can become a total replacement for the legacy stuff that is available such as the PEAR libraries and the likes of Drupal writing their own abstraction layer on top of it ... along with a number of other projects who are now doing the same thing ... shows that PDO is not creating the common platform it was supposed to :( -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
In previous experience with questions such as these, you will get several types of individual responses to usages of the software. Some good, some bad, depending on the experience level of the commenter with both the language and the code in question. It's a combination of your current understanding of php and the associated usages of other languages, and what you want to know. Don't trust what people say, trust what feels right at the current time of your usage of the php library available/your experience level, and what you currently know how to use. From my experience with several languages, once you know the basics, even if you do re-invent the 'wheel', so did firestone,michelin, and goodyear, and they're not complaining. And you'll feel better for reinventing, than using someone elses. I think this ^^^ advice is brilliant, understated; nothing replaces integration of one's own thorough understanding. Govinda govinda(DOT)webdnatalk(AT)gmail(DOT)com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On Tue, Dec 14, 2010 at 03:10:56AM -0800, Sam Smith wrote: Searching for PHP CRUD in hopes of learning the best way to access databases and to use PEAR or what I came across PDO. I want to know the communities opinion of PDO: everyone uses it or no one uses it or it's great or what? I use PDO within a class which handles various housekeeping (error handling etc.) for everything. PDO handles all the popular RDBMSes (as far as I know). It can also sanitize queries to avoid SQL injection. Simple interface. It's also part of PHP, meaning it's well tested and solid. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO: good, popular?
On Tuesday, December 14, 2010 1:02:33 pm Lester Caine wrote: la...@garfieldtech.com wrote: I'm the DB maintainer for Drupal 7, and we rebuilt our entire DB layer on top of PDO. It's a rather nice API, although as others have noted it does not abstract away SQL entirely; it abstracts the API calls you need to use to get to SQL. We then built a layer on top of that which does abstract away most database weirdness using fluent query builders. It's much lighter-weight than an ORM. I'm in the process of spinning it off as a stand-alone library because we think it's that cool, but it's not completely divorced from Drupal yet. Stay tuned. :-) Larry - how many databases does it actually work with? Having rebuilt the DB layer using PDO did you actually gain anything? Drupal 6 and earlier supported MySQL and, kinda sorta, Postgres, maybe. Drupal 7 ships with support for MySQL, Postgres, and SQLite out of the box and add-on modules provide support for Oracle and MS SQL, within reason. So we increased our DB support from 1.5 to 5, essentially. We also gained, as part of the rewrite, untyped prepared statements, transactions, and master/slave support (although that's nothing to do with PDO per se, just our layer on top of it). And that allowed us, in turn, to build type-safe query builders, support for MERGE queries, and all kinds of other fun stuff on top of that. PDO still needs a number of areas finishing before it can become a total replacement for the legacy stuff that is available such as the PEAR libraries and the likes of Drupal writing their own abstraction layer on top of it ... along with a number of other projects who are now doing the same thing ... shows that PDO is not creating the common platform it was supposed to :( That is, sadly, true. PDO is not a complete and perfect DB library, in part because there are few people who work on it, and fewer still who understand all of the vendor-specific issues at hand and the vendors have been very slow to lend a hand, preferring to work on proprietary APIs. It's quite unfortunate, but I still consider PDO an overall win. If anyone knows C and wants to make a name for themselves in the PHP world, PDO is looking for some heroes. :-) --Larry Garfield -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php