php-general Digest 29 Apr 2011 11:37:37 -0000 Issue 7288
Topics (messages 312545 through 312564):
Re: Flattery will get you nowhere
312545 by: Nathan Rixham
312546 by: Nathan Rixham
312554 by: Robert Cummings
What's faster using if else or arrays?
312547 by: dholmes1031.gmail.com
312548 by: Jim Giner
312550 by: Andre Polykanine
312551 by: Andre Polykanine
312552 by: dholmes1031.gmail.com
312553 by: Jim Giner
312555 by: Robert Cummings
312556 by: Geoff Lane
312557 by: Jim Giner
312561 by: Ashley Sheridan
Re: Javascript detection
312549 by: Geoff Lane
gd Graphics Library Question (EXIF)
312558 by: Mitch
PHP delete confirmation
312559 by: Chris Stinemetz
312560 by: admin.buskirkgraphics.com
312562 by: Sharl.Jimh.Tsin
312563 by: Geoff Lane
RelaxNG parser in PHP?
312564 by: Frank Arensmeier
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 ---
tedd wrote:
At 4:58 PM -0400 4/27/11, Robert Cummings wrote:
Tedd who?
;)
Cheers,
Rob.
Rob what?
;-)
Cheers,
tedd
flirting?
--- End Message ---
--- Begin Message ---
tedd wrote:
At 4:58 PM -0400 4/27/11, Robert Cummings wrote:
Tedd who?
;)
Cheers,
Rob.
Rob what?
;-)
Cheers,
tedd
flirting?
--- End Message ---
--- Begin Message ---
On 11-04-28 05:23 PM, Nathan Rixham wrote:
tedd wrote:
At 4:58 PM -0400 4/27/11, Robert Cummings wrote:
Tedd who?
;)
Cheers,
Rob.
Rob what?
;-)
Cheers,
tedd
flirting?
Flirting will get you everywhere *bats eyelids*
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
I'm working on a project and I was wondering if I should use if else's or
arrays ??
Example
If($foo= 5)
{
$dothis
}
ElseIf($foo= 3)
{
$dothis
}
Else{ $donothing }
Or put it in some short of arrays and pregmatch what would be the best to use
and easiest to read
Sent via BlackBerry from T-Mobile
--- End Message ---
--- Begin Message ---
how many entries are you talking about, ie., how many conditions? Obviously
if you have more than 4-5 it's going to be easier to code up as a case
statement (?) rather than an if/else.
Never in all my days have I ever heard of using an array for such a
determination though.
(remainder deleted for all reader's sakes :) )
--- End Message ---
--- Begin Message ---
Hello Dholmes1031,
I would write it like this:
switch($foo) {
case 5: $dothis; break;
case 3: $dothat; break;
default: $donothing; break;
}
--
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
------------ Original message ------------
From: [email protected] <[email protected]>
To: [email protected]
Date created: , 12:30:31 AM
Subject: [PHP] What's faster using if else or arrays?
I'm working on a project and I was wondering if I should use if else's or
arrays ??
Example
If($foo= 5)
{
$dothis
}
ElseIf($foo= 3)
{
$dothis
}
Else{ $donothing }
Or put it in some short of arrays and pregmatch what would be the best to use
and easiest to read
Sent via BlackBerry from T-Mobile
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hello Jim,
I heard of arrays in the following context:
if (($foo==5) || ($foo=="orange") || ($foo==88) ......
So *that* would be done much better and cleaner with arrays.
$FoosArray=array(5, "orange", 88);
if (in_array($foo, $FoosArray)) { ... }
--
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
------------ Original message ------------
From: Jim Giner <[email protected]>
To: [email protected]
Date created: , 12:36:26 AM
Subject: [PHP] Re: What's faster using if else or arrays?
how many entries are you talking about, ie., how many conditions?
Obviously
if you have more than 4-5 it's going to be easier to code up as a case
statement (?) rather than an if/else.
Never in all my days have I ever heard of using an array for such a
determination though.
(remainder deleted for all reader's sakes :) )
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Thanks switch and case seems to be more faster for the job and a lot cleaner
------Original Message------
From: Andre Polykanine
To: [email protected]
Cc: [email protected]
Subject: Re: [PHP] What's faster using if else or arrays?
Sent: Apr 28, 2011 6:17 PM
Hello Dholmes1031,
I would write it like this:
switch($foo) {
case 5: $dothis; break;
case 3: $dothat; break;
default: $donothing; break;
}
--
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion
------------ Original message ------------
From: [email protected] <[email protected]>
To: [email protected]
Date created: , 12:30:31 AM
Subject: [PHP] What's faster using if else or arrays?
I'm working on a project and I was wondering if I should use if else's or
arrays ??
Example
If($foo= 5)
{
$dothis
}
ElseIf($foo= 3)
{
$dothis
}
Else{ $donothing }
Or put it in some short of arrays and pregmatch what would be the best to use
and easiest to read
Sent via BlackBerry from T-Mobile
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sent via BlackBerry from T-Mobile
--- End Message ---
--- Begin Message ---
Arrays - using a silly construct that probably still takes as much time to
evaluate machine-wise as anything else. And as far as readability goes, it
is even sillier. IMO.
(remainder deleted for readers' sakes :) )
--- End Message ---
--- Begin Message ---
On 11-04-28 06:37 PM, [email protected] wrote:
Thanks switch and case seems to be more faster for the job and a lot cleaner
------Original Message------
From: Andre Polykanine
To: [email protected]
Cc: [email protected]
Subject: Re: [PHP] What's faster using if else or arrays?
Sent: Apr 28, 2011 6:17 PM
Hello Dholmes1031,
I would write it like this:
switch($foo) {
case 5: $dothis; break;
case 3: $dothat; break;
default: $donothing; break;
}
This sounds like a job for *dun dun dun* GOTO!
Kidding, of course ;)
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
On Thursday, April 28, 2011, Jim Giner wrote:
> Arrays - using a silly construct that probably still takes as much
> time to evaluate machine-wise as anything else. And as far as
> readability goes, it is even sillier. IMO.
I don't know so much about that ...
I'll use a global array to define an application-wide set and then use
in_array to branch dependent on whether some variable has a value that
is or is not a member of that set. Using a series of predicates in a
multiple OR, or using switch is a non-started for me for maintenance
reasons, and the alternative of storing the set of values in a
database is a lot slower. Here's an example:
FWIW, I've got a mapping application. Users can click on a map tile to
indicate a point of interest. However, they can also click on zoom
buttons, or pan buttons. These buttons are named 'plus', 'minus',
'left', 'right', 'up', and 'down' and I have these names in an
application-wide array:
$controls = array ('plus', 'minus', 'left', 'right', 'up', 'down');
The way that these map view controls are handled is very different to
the way a click on a map tile is handled. Somehow, the code is more
readable with:
if (in_array($clicked, $controls)){
// ...
}
than with:
if ($clicked == 'plus' || $clicked == 'minus' || $clicked == 'left' || $clicked
== 'right' || $clicked == 'up' || $clicked == 'down'){
// ...
}
Even using switch isn't as clear IMO as that can intersperse the
options with several lines of code, which can make the logic harder to
spot.
However, the real benefit of using an array comes in making the code
easier to maintain. Drawing my map is a library routine, as is the
handler for the controls. However, the handling of clicks on map tiles
is different for each of the eight or nine contexts in which the
mapping is used. So the best way IMO of coding this is to test in each
page which element has been clicked and to either call a library
routine or a context-specific handler from there.
Now say, for example, that I want to augment the zoom functionality by
having a 'slider' that permits the user to go directly to a desired
zoom level. I can redefine the set of controls by simply changing the
global array. However, using the long if construct mandates that I
must amend the code of every page that uses the mapping, which makes
for a lot of extra work and is just plain silly IMO. IOW, using an
array can help avoid coding inconsistencies.
--
Geoff
--- End Message ---
--- Begin Message ---
Obviously you have designed a search/decision mechanism that suits your
needs. The OP did not present a problem of such magnitude. He only asked
how to handle a decision process the most efficient way - with no mention of
higher goals such as yours.
didn't mean to offend anyone who has made a powerful use of the array
constuct.
"Geoff Lane" <[email protected]> wrote in message
news:[email protected]...
> On Thursday, April 28, 2011, Jim Giner wrote:
--- End Message ---
--- Begin Message ---
On Thu, 2011-04-28 at 22:12 -0400, Jim Giner wrote:
> Obviously you have designed a search/decision mechanism that suits your
> needs. The OP did not present a problem of such magnitude. He only asked
> how to handle a decision process the most efficient way - with no mention of
> higher goals such as yours.
>
> didn't mean to offend anyone who has made a powerful use of the array
> constuct.
>
> "Geoff Lane" <[email protected]> wrote in message
> news:[email protected]...
> > On Thursday, April 28, 2011, Jim Giner wrote:
>
>
>
I see no problem using in_array() for situations like this, and they can
be used in conjunction with a switch if you want as well:
switch(true)
{
case in_array($needle, array('foo','bar','wtf')):
{
// do something
break;
}
case ($needle == 88):
{
// something else
break;
}
}
And it's still quite readable as long as you get your indentation right.
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Thursday, April 28, 2011, Ashley Sheridan wrote:
> I'm not sure if my earlier reply got through, but here it is again (or
> at least the general gist of it)
Many thanks. I got your info the first time around but didn't respond
directly to you as Tedd made similar comments and I'd responded to his
post.
> Like everyone has mentioned thus far, it's better to use progressive
> enhancement or try to avoid relying on Javascript at all. Even a website
> as complex as Facebook allows users to go on it without needing a
> browser that runs Javascript. Something as complex as Google Docs has a
> very clear need for Javascript though, so you wouldn't expect that to
> work without it.
In my case, one of the controls I'm considering is a tiled map with up
to 16 tiles. This is on a page with four tabbed sections that takes
several seconds to load at broadband speeds. Also, the nature of the
site means that people may need to access it and use this form while
connected via mobile broadband or even GSM; connection media that are
usually both slow and paid for per unit of data transfer. I need to
record in hidden input fields the location of where a user clicks on
the map and also echo that click back in the form of a marker overlaid
on the clicked tile. Using AJAX, I can update just the two fields plus
one image. Without Javascript, the extra bandwidth needed to
unnecessarily download the entire page multiple times will cost my
users both time and money. So while I must ensure the site works
without Javascript, I really need the optimisation that JS brings.
> Lastly, if you're creating the website for a government or business, you
> really need to make it work without Javascript, as a lot of countries
> make it illegal to discriminate against a disability, which you would be
> doing if you made a site that was unusable without Javascript. After
> all, there are many speech and Braille browsers out there that can't
> take advantage of Javascript, and a lot of Javascript apps which require
> mouse interaction to run (mouseover/hover events, etc)
AIUI, a lot of countries (mine included) make it unlawful to knowingly
discriminate against the disabled. However, The Disability
Discrimination Act requires only that reasonable steps be taken to
avoid discrimination ... and making stuff accessible to the disabled
at considerable inconvenience and/or expense to everyone else is not
considered reasonable. Now where I can, I'll produce stuff that is
enhanced by images, colour, JS etc. but will still be usable in Lynx.
However, some stuff (e.g. mapping) won't work without graphics and so
is inherently unavailable to the visually impaired. It makes no sense
whatever to try to make such content work in speech and Braille
browsers. Thus making a site that's unusable without Javascript
doesn't necessarily constitute unlawful discrimination!
--
Geoff
--- End Message ---
--- Begin Message ---
I have written a lightweight, easy to use photo album "system" in
HTML/PHP/MySQL.In addition to the Photo Album side I have written a
series of Admin Utilities to manage it with. One of the administrative
utilities uploads photos from my local drive, resizes them to be more
efficient on disk space, creates thumbnails and populates the database
with as much "default" data as can be deduced.
After all of this was written, I decided to see if I could pull EXIF
data to supply some of the technical data for the DB. To my surprise,
the only EXIF data in the JPEG files was data in the File, Computed and
Comments sections.
Why don't the gd utilities retain the original EXIF data? Is there any
way to do so? I use the following gd utilities to resize and create the
new JPEG image files:
imagecreatefromjpeg
imagesx
imagesy
imagercreatetruecolor
imagecopyresized
imagejpeg
Thanks in advance,
Mitch
--- End Message ---
--- Begin Message ---
I have been trying to figure out how to add delete confirmation for
the bellow snippet of code. I would prefer not to use javascript. Can
anyone offer any advise on how to right the delete confirmation in
PHP?
Thank you in advance.
P.S. I apologize for the indention. For some reason gmail messes it up.
<?php
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['Date'] . '</td>';
echo '<td>' . $row['StoreInfo'] . '</td>';
echo '<td>' . $row['Address'] . '</td>';
echo '<td>' . $row['Type'] . '</td>';
echo '<td>' . $row['EngTech'] . '</td>';
echo '<td>' . $row['StoreManager'] . '</td>';
echo '<td>' . $row['BBtime'] . '</td>';
echo '<td>' . $row['BBup'] . '</td>';
echo '<td>' . $row['BBdown'] . '</td>';
echo '<td>' . $row['SiteSect'] . '</td>';
echo '<td>' . $row['VoiceCall'] . '</td>';
echo '<td>' . $row['Comments'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id']
.'">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id']
.'">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
--- End Message ---
--- Begin Message ---
This can be done in the delete.php file OR use javascript onClick to confirm
the intent.
Delete.php
<?php
If($_GET['confirm'] == "Yes")
{
//Delete actions
}else If($_GET['confirm'] == "No")
{
//No Delete actions.
}else{
//display a delete confirmation and remember to carry required information
like the value you passed for delete.
}
?>
Personally I would use the javascript page navigation is senseless if they
miss click.
Javascript: Small and simple javascript.
onclick="return confirm('Are you sure you want to delete?')"
Richard L. Buskirk
-----Original Message-----
From: Chris Stinemetz [mailto:[email protected]]
Sent: Friday, April 29, 2011 12:33 AM
To: [email protected]
Subject: [PHP] PHP delete confirmation
I have been trying to figure out how to add delete confirmation for
the bellow snippet of code. I would prefer not to use javascript. Can
anyone offer any advise on how to right the delete confirmation in
PHP?
Thank you in advance.
P.S. I apologize for the indention. For some reason gmail messes it up.
<?php
// loop through results of database query, displaying them in the
table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['Date'] . '</td>';
echo '<td>' . $row['StoreInfo'] . '</td>';
echo '<td>' . $row['Address'] . '</td>';
echo '<td>' . $row['Type'] . '</td>';
echo '<td>' . $row['EngTech'] . '</td>';
echo '<td>' . $row['StoreManager'] . '</td>';
echo '<td>' . $row['BBtime'] . '</td>';
echo '<td>' . $row['BBup'] . '</td>';
echo '<td>' . $row['BBdown'] . '</td>';
echo '<td>' . $row['SiteSect'] . '</td>';
echo '<td>' . $row['VoiceCall'] . '</td>';
echo '<td>' . $row['Comments'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id']
.'">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id']
.'">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
yes,i agree with you,Richard L. Buskirk. process by client-side
script,such as javascript is the best and convenient way.
Best regards,
Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)
2011/4/29 <[email protected]>:
> This can be done in the delete.php file OR use javascript onClick to confirm
> the intent.
>
>
> Delete.php
> <?php
> If($_GET['confirm'] == "Yes")
> {
> //Delete actions
> }else If($_GET['confirm'] == "No")
> {
> //No Delete actions.
> }else{
> //display a delete confirmation and remember to carry required information
> like the value you passed for delete.
> }
> ?>
>
>
> Personally I would use the javascript page navigation is senseless if they
> miss click.
>
> Javascript: Small and simple javascript.
>
> onclick="return confirm('Are you sure you want to delete?')"
>
>
>
> Richard L. Buskirk
>
>
> -----Original Message-----
> From: Chris Stinemetz [mailto:[email protected]]
> Sent: Friday, April 29, 2011 12:33 AM
> To: [email protected]
> Subject: [PHP] PHP delete confirmation
>
> I have been trying to figure out how to add delete confirmation for
> the bellow snippet of code. I would prefer not to use javascript. Can
> anyone offer any advise on how to right the delete confirmation in
> PHP?
>
> Thank you in advance.
>
> P.S. I apologize for the indention. For some reason gmail messes it up.
>
> <?php
> // loop through results of database query, displaying them in the
> table
> while($row = mysql_fetch_array( $result )) {
>
> // echo out the contents of each row into a table
> echo "<tr>";
> echo '<td>' . $row['Name'] . '</td>';
> echo '<td>' . $row['Date'] . '</td>';
> echo '<td>' . $row['StoreInfo'] . '</td>';
> echo '<td>' . $row['Address'] . '</td>';
> echo '<td>' . $row['Type'] . '</td>';
> echo '<td>' . $row['EngTech'] . '</td>';
> echo '<td>' . $row['StoreManager'] . '</td>';
> echo '<td>' . $row['BBtime'] . '</td>';
> echo '<td>' . $row['BBup'] . '</td>';
> echo '<td>' . $row['BBdown'] . '</td>';
> echo '<td>' . $row['SiteSect'] . '</td>';
> echo '<td>' . $row['VoiceCall'] . '</td>';
> echo '<td>' . $row['Comments'] . '</td>';
> echo '<td><a href="edit.php?id=' . $row['id']
> .'">Edit</a></td>';
> echo '<td><a href="delete.php?id=' . $row['id']
> .'">Delete</a></td>';
> echo "</tr>";
> }
>
> // close table>
> echo "</table>";
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Friday, April 29, 2011, [email protected] wrote:
> Personally I would use the javascript page navigation is senseless if they
> miss click.
> Javascript: Small and simple javascript.
> onclick="return confirm('Are you sure you want to delete?')"
Personally, I'd use Javascript and also check that the form was
submitted after the client-side check. So something like a hidden
field ('jstest') in the client-side form that is set to 1 by the
onClick event prior to showing the confirmation box. Then in the
handling PHP:
if ($_POST['jstest'] == 1){
// the client called us via Javascript::confirm, so we know the
// use really wants to delete
} else {
// We weren't called via Javascript::confirm, so we need to
// handle the confirmation in PHP
}
HTH,
--
Geoff
--- End Message ---
--- Begin Message ---
Hello List!
Currently I am using a pear package in one of my projects to parse and query
XML DTD files. The package is called XML_DTD 0.5.2 and includes the so called
XML_DTD_Parser. One of the purposes of this class is to parse a given DTD file
and return that file as a tree like object. With the help of that object, I can
find out valid children (and valid attributes) for a given tag (which is what I
am using the XML_DTD class for). Now I am looking for a similar class in order
to parse RelaxNG (alternatively Schematron) files.
I have search Google high and low but was not able to find anything suitable.
Any hints are more than welcome!
Regards,
/frank
--- End Message ---