php-general Digest 12 Mar 2013 02:50:38 -0000 Issue 8158
Topics (messages 320458 through 320479):
Re: XML to Array
320458 by: Bastien Koert
320470 by: Karl DeSaulniers
320479 by: Karl DeSaulniers
Re: Generating CRUD code for normalized db
320459 by: Ashley Sheridan
320460 by: Jim Giner
320461 by: Gary
320462 by: Samuel Lopes Grigolato
320463 by: Jim Giner
Re: Does Scope-Resolution Operator Always Follow 'parent'?
320464 by: David Harkness
Imagick morphImages
320465 by: Leonard Burton
320466 by: Jen Rasmussen
SPL RecursiveArrayIterator::offset(Un)Set has no effect on instance created
with ArrayObject
320467 by: NaMarPi
UNLESS Statement Equivalent
320468 by: Angela Barone
320469 by: Jonathan Sundquist
320471 by: Ashley Sheridan
320472 by: Maciek Sokolewicz
320473 by: Angela Barone
320474 by: Jonathan Sundquist
320475 by: Angela Barone
320476 by: Jonathan Sundquist
320477 by: Angela Barone
320478 by: Larry Garfield
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 ---
On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers <k...@designdrumm.com> wrote:
>
> On Mar 10, 2013, at 6:03 AM, richard gray wrote:
>
>> On 10/03/2013 11:47, Karl DeSaulniers wrote:
>>>
>>> Hi Guys,
>>> I am hoping someone can guide me or help me fix this issue.
>>> I have been lost in the code for some time now.
>>> I am trying to get the attributes of an xml node.
>>> I have this code:
>>> [snip]
>>
>> this may help ->
>> http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing
>>>
>>> I do admit I haven't the foggiest idea what I am doing here, so I am
>>> noobing out here on how this php function is really working.
>>> I got it off php.net and am trying to implement it in my code. Without my
>>> addition it works well except it doesn't grab any attributes
>>> which I need in order for my script to work properly.
>>>
>>> Any ideas on what I am doing wrong?
>>>
>>> TIA,
>>
>>
>> HTH
>> rich
>
>
>
> Thanks rich,
> That uses simpleXML. I am using xml_parse_create.
> Any ideas for xml_parse_create? I really like the way this function
> puts everything into an array that I can traverse. I only need it to put
> the attribute values in the array for the corresponding node and I am done.
> *Sigh
>
> Thanks for your help,
>
> Best,
>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
I came across this XML to JSON to an array some time ago. It might be something
function xmlToArray($xml)
{
return json_decode(json_encode((array) simplexml_load_string($xml)),1);
}
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
On Mar 11, 2013, at 8:22 AM, Bastien Koert wrote:
On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers <k...@designdrumm.com
> wrote:
On Mar 10, 2013, at 6:03 AM, richard gray wrote:
On 10/03/2013 11:47, Karl DeSaulniers wrote:
Hi Guys,
I am hoping someone can guide me or help me fix this issue.
I have been lost in the code for some time now.
I am trying to get the attributes of an xml node.
I have this code:
[snip]
this may help ->
http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing
I do admit I haven't the foggiest idea what I am doing here, so I
am
noobing out here on how this php function is really working.
I got it off php.net and am trying to implement it in my code.
Without my
addition it works well except it doesn't grab any attributes
which I need in order for my script to work properly.
Any ideas on what I am doing wrong?
TIA,
HTH
rich
Thanks rich,
That uses simpleXML. I am using xml_parse_create.
Any ideas for xml_parse_create? I really like the way this function
puts everything into an array that I can traverse. I only need it
to put
the attribute values in the array for the corresponding node and I
am done.
*Sigh
Thanks for your help,
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
I came across this XML to JSON to an array some time ago. It might
be something
function xmlToArray($xml)
{
return json_decode(json_encode((array) simplexml_load_string($xml)),
1);
}
--
Bastien
Cat, the other other white meat
Thanks Bastien!
That worked very well. I now see the attributes. However it does not
load the root node?
I am going to need that node to display too. Any thoughts as to why it
is not showing?
I just copied and pasted your code. I'm going to look at some docs to
see if I can find out why,
but if you know, please let me know your solution. Thanks again.
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--- End Message ---
--- Begin Message ---
On Mar 11, 2013, at 8:22 AM, Bastien Koert wrote:
On Sun, Mar 10, 2013 at 6:28 PM, Karl DeSaulniers <k...@designdrumm.com
> wrote:
On Mar 10, 2013, at 6:03 AM, richard gray wrote:
On 10/03/2013 11:47, Karl DeSaulniers wrote:
Hi Guys,
I am hoping someone can guide me or help me fix this issue.
I have been lost in the code for some time now.
I am trying to get the attributes of an xml node.
I have this code:
[snip]
this may help ->
http://stackoverflow.com/questions/1156957/php-xml-attribute-parsing
I do admit I haven't the foggiest idea what I am doing here, so I
am
noobing out here on how this php function is really working.
I got it off php.net and am trying to implement it in my code.
Without my
addition it works well except it doesn't grab any attributes
which I need in order for my script to work properly.
Any ideas on what I am doing wrong?
TIA,
HTH
rich
Thanks rich,
That uses simpleXML. I am using xml_parse_create.
Any ideas for xml_parse_create? I really like the way this function
puts everything into an array that I can traverse. I only need it
to put
the attribute values in the array for the corresponding node and I
am done.
*Sigh
Thanks for your help,
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
I came across this XML to JSON to an array some time ago. It might
be something
function xmlToArray($xml)
{
return json_decode(json_encode((array) simplexml_load_string($xml)),
1);
}
--
Bastien
Cat, the other other white meat
Actually no, I don't need the root node after all.
Looks like it finally works! :)
Thank you Bastien! Nice one-liner.
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--- End Message ---
--- Begin Message ---
Gary <listgj-phpgene...@yahoo.co.uk> wrote:
>Ashley Sheridan wrote:
>
>> In any case, you could probably take something you like from another
>> framework if you have the time/inclination/capability.
>
>I honestly think I am simply going to write the shit myself. The CRUD
>pages, I mean. I see no reason to keep searching for what, for me, is
>very very basic functionaility. The inadequacies of so much Free Open
>Source Shit never ceases to amaze me. Too many wannabes doing it who
>overestimate their own capabilities and have no clue what is really
>required in the real world.
Well, you don't really help yourself with a reply like that to the very people
helping you.
I and others have pointed you towards open source solutions, the fact you don't
want to put any effort in to make them work for you is not because of the state
of open source software.
Your behaviour though makes me less-inclined to offer help in the future.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 3/11/2013 10:14 AM, Ashley Sheridan wrote:
Gary <listgj-phpgene...@yahoo.co.uk> wrote:
Ashley Sheridan wrote:
In any case, you could probably take something you like from another
framework if you have the time/inclination/capability.
I honestly think I am simply going to write the shit myself. The CRUD
pages, I mean. I see no reason to keep searching for what, for me, is
very very basic functionaility. The inadequacies of so much Free Open
Source Shit never ceases to amaze me. Too many wannabes doing it who
overestimate their own capabilities and have no clue what is really
required in the real world.
Well, you don't really help yourself with a reply like that to the very people
helping you.
I and others have pointed you towards open source solutions, the fact you don't
want to put any effort in to make them work for you is not because of the state
of open source software.
Your behaviour though makes me less-inclined to offer help in the future.
Thanks,
Ash
http://www.ashleysheridan.co.uk
egg-zactly! With comments like these, why would he ever expect a
'courtesy' reply??
--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> Gary <listgj-phpgene...@yahoo.co.uk> wrote:
>>The inadequacies of so much Free Open Source Shit never ceases to
>>amaze me. Too many wannabes doing it who overestimate their own
>>capabilities and have no clue what is really required in the real
>>world.
>
> Well, you don't really help yourself with a reply like that to the very
> people helping you.
I wasn't aware you would feel that the cap fitted.
> I and others have pointed you towards open source solutions, the fact
> you don't want to put any effort in to make them work for you is not
> because of the state of open source software.
If you think that "solutions" are things which do not work, following
precisely the instructions on those "solutions'" websites, then I feel
sorry for you.
--
Gary Please do NOT send me 'courtesy' replies off-list.
--- End Message ---
--- Begin Message ---
If you don't appreciate Open Source "solutions", why are you losing time on
a Open Source Project Mailing List? Go pay (a lot) for a handholding
framework and be happy =), just don't demotivate the ones who bring free
software to reality, even if the free software is not as good as you would
like.
On Mon, Mar 11, 2013 at 11:51 AM, Gary <listgj-phpgene...@yahoo.co.uk>wrote:
> Ashley Sheridan wrote:
> > Gary <listgj-phpgene...@yahoo.co.uk> wrote:
>
> >>The inadequacies of so much Free Open Source Shit never ceases to
> >>amaze me. Too many wannabes doing it who overestimate their own
> >>capabilities and have no clue what is really required in the real
> >>world.
> >
> > Well, you don't really help yourself with a reply like that to the very
> > people helping you.
>
> I wasn't aware you would feel that the cap fitted.
>
> > I and others have pointed you towards open source solutions, the fact
> > you don't want to put any effort in to make them work for you is not
> > because of the state of open source software.
>
> If you think that "solutions" are things which do not work, following
> precisely the instructions on those "solutions'" websites, then I feel
> sorry for you.
>
> --
> Gary Please do NOT send me 'courtesy' replies off-list.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Gary,
Until I read this post of yours I never knew what CRUD stood for, let
alone knew that such an acronym was even needed in the world.
If you are complaining about not being able to find software written to
handle Creating, Reading, Updating and Deleting data in a table or
tables that works to your satisfaction, remember the adage "you get what
you pay for"?
On the other hand, why would you expect such basic software to be
pre-written to your satisfaction? Have you ever known a programmer that
was completely happy with someone else's software?
And on the third hand, what kind of a programmer looks for such
software? Haven't you already written your own CRUD lines yet?
Perhaps you just need to begin this day over again and try to be nicer.
--- End Message ---
--- Begin Message ---
Hi Eric,
On Sun, Mar 10, 2013 at 8:21 PM, Eric James Michael Ritz <
lobbyjo...@gmail.com> wrote:
> I have a question about the `parent` keyword: is there any valid
> situation where it can appear without the `::` operator following?
>
I wouldn't have thought it possible, but I just found one case with PHP 5.4
where it can appear as the keyword without a trailing "::". Apparently you
can use it to instantiate the parent class just as you can with "new self".
class Foo { }
class Bar extends Foo {
public function foo() {
return new parent;
}
}
I think you'll be safe if you can highlight it only when preceded by "new"
or followed by "::".
David
--- End Message ---
--- Begin Message ---
HI,
*Imagick::morphImages* ( int $number_frames )
http://php.net/manual/en/imagick.morphimages.php
Would someone please reply with how to add the two images for this?
None of the search results come back with anything other than the
auto-generated info on the imagick class.
Many Thanks!
--
Leonard Burton, N9URK
leonardbur...@gmail.com
"The prolonged evacuation would have dramatically affected the
survivability of the occupants."
--- End Message ---
--- Begin Message ---
I found the following code here: https://gist.github.com/mywebpower/1035026
It appears 2 years old though ...
<?php
/**
* GD+Imagick = morphing
*
* @param string $fromPath
* @param string $toPath
* @param string $outPath
* @param integer $frame OPTIONAL
* @param integer $delay OPTIONAL
*/
function morph($fromPath, $toPath, $outPath, $frame=10, $delay=1) {
$im = new Imagick();
$gf = imagecreatefromjpeg($fromPath);
$gt = imagecreatefromjpeg($toPath);
$sz = getimagesize($toPath);
$wkImg = '__work__.jpg';
for($i=1; $i<=$frame; $i++) {
imagecopymerge($gf, $gt, 0,0, 0,0, $sz[0],$sz[1], (100/$frame)*$i);
imagejpeg($gf, $wkImg);
$tmp = new Imagick($wkImg);
$tmp->setFormat('gif');
$tmp->setImageDelay($delay*100);
$im->addImage($tmp);
$tmp->destroy();
unlink($wkImg);
}
$im->writeImages($outPath, true);
$im->destroy();
imagedestroy($gf);
imagedestroy($gt);
}
// ex
morph('a.jpg', 'b.jpg', 'out.gif', 10, 0.1);
?>
Hope it helps,
Jen
-----Original Message-----
From: Leonard Burton [mailto:leonardbur...@gmail.com]
Sent: Monday, March 11, 2013 1:26 PM
To: php-gene...@lists.php.net
Subject: [PHP] Imagick morphImages
HI,
*Imagick::morphImages* ( int $number_frames )
http://php.net/manual/en/imagick.morphimages.php
Would someone please reply with how to add the two images for this?
None of the search results come back with anything other than the
auto-generated info on the imagick class.
Many Thanks!
--
Leonard Burton, N9URK
leonardbur...@gmail.com
"The prolonged evacuation would have dramatically affected the survivability
of the occupants."
--- End Message ---
--- Begin Message ---
Hello All,
It seems to me that an instance of RecursiveIteratorIterator with ArrayObject
has no effect
when calling RecursiveArrayIterator::offsetUnset or
RecursiveArrayIterator::offsetSet methods.
But everything works fine when the iterator is created with a json_decoded -
json_encoded array.
I expect the same behavior of these two iterators, but maybe I am wrong.
Any guidance would be appreciated.
Test script:
----------------------------------
function example() {
$array = array (
'name' => 'text',
'items' => array (
'0' => array ( 'phrase' => 'text text', ),
'1' => array ( 'phrase' => 'text text text', ),
'ctrl' => array( '0' => '1', ),
),
);
$array_object = json_decode( json_encode( $array ));
$iterator = new RecursiveIteratorIterator( new
RecursiveArrayIterator( $array_object ),
RecursiveIteratorIterator::CHILD_FIRST );
// comment these two lines and see the nice execution
$array_object = new ArrayObject( $array, 0, "RecursiveArrayIterator" );
$iterator = new RecursiveIteratorIterator(
$array_object->getIterator(), RecursiveIteratorIterator::CHILD_FIRST );
foreach( $iterator as $key => $value ) {
$array_copy = $iterator->getInnerIterator()->getArrayCopy();
$keys = array_keys( $array_copy );
$numeric_keys = array_filter( $keys, 'is_numeric' );
if( count( $numeric_keys ) !== 0 && count( $keys ) == count(
$numeric_keys ) + 1 ) {
$ctrl = $array_copy['ctrl'];
$iterator->getInnerIterator()->offsetUnset( 'ctrl' );
foreach( $iterator->getInnerIterator() as $ctrl_value => $value ) {
if( in_array( $ctrl_value, $ctrl )) {
$iterator->getInnerIterator()->getChildren()->offsetSet(
'ctrl', $ctrl_value );
} else {
$iterator->getInnerIterator()->getChildren()->offsetSet(
'ctrl', '' );
}
}
// print_r( $iterator->getInnerIterator() );
}
}
print_r( object_to_array( $array_object ));
// print_r( iterator_to_array( $iterator ));
}
// helper method
function object_to_array( $object ) {
if( ! is_array( $object ) && ! is_object( $object )) {
return $object;
}
if( is_object( $object )) {
$object = get_object_vars( $object );
}
return array_map( __FUNCTION__, $object );
}
example();
Expected result:
--------------------------
[11-Mar-2013 18:24:48 UTC] Array
(
[name] => text
[items] => Array
(
[0] => Array
(
[phrase] => text text
[ctrl] =>
)
[1] => Array
(
[phrase] => text text text
[ctrl] => 1
)
)
)
--- End Message ---
--- Begin Message ---
I'm looking for an 'unless' statement, but as far as I can tell, PHP
doesn't have one. Hopefully someone can help me rewrite my statement.
In English, I want to say: "always do something UNLESS these 3
conditions are met".
The best I've been able to come up with in PHP is this:
if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
($current_dt < ($saved_dt + 3600)) ) {
return;
} else {
$query = "UPDATE `table` SET `hits` = '$count', `agent` = '$agent',
`ts` = '$date_time' WHERE `page` = '$page'";
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
}
However, I've read where this is not really acceptable. Can someone
help me eliminate the 'else' portion of this if statement?
Thank you,
Angela
P.S. I realize the above isn't complete code but it should still be clear. If
not, let me know.
--- End Message ---
--- Begin Message ---
Since you already have the return statement with the if statement the else
isn't required. If those three statements are true you would exit the call
any ways
On Mar 11, 2013 4:33 PM, "Angela Barone" <ang...@italian-getaways.com>
wrote:
> I'm looking for an 'unless' statement, but as far as I can tell,
> PHP doesn't have one. Hopefully someone can help me rewrite my statement.
>
> In English, I want to say: "always do something UNLESS these 3
> conditions are met".
>
> The best I've been able to come up with in PHP is this:
>
> if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
> ($current_dt < ($saved_dt + 3600)) ) {
> return;
> } else {
> $query = "UPDATE `table` SET `hits` = '$count', `agent` =
> '$agent', `ts` = '$date_time' WHERE `page` = '$page'";
> $result = mysql_query($query) or die ('Error! -- ' .
> mysql_error());
> }
>
> However, I've read where this is not really acceptable. Can
> someone help me eliminate the 'else' portion of this if statement?
>
> Thank you,
> Angela
>
> P.S. I realize the above isn't complete code but it should still be
> clear. If not, let me know.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Mon, 2013-03-11 at 16:38 -0500, Jonathan Sundquist wrote:
> Since you already have the return statement with the if statement the else
> isn't required. If those three statements are true you would exit the call
> any ways
> On Mar 11, 2013 4:33 PM, "Angela Barone" <ang...@italian-getaways.com>
> wrote:
>
> > I'm looking for an 'unless' statement, but as far as I can tell,
> > PHP doesn't have one. Hopefully someone can help me rewrite my statement.
> >
> > In English, I want to say: "always do something UNLESS these 3
> > conditions are met".
> >
> > The best I've been able to come up with in PHP is this:
> >
> > if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
> > ($current_dt < ($saved_dt + 3600)) ) {
> > return;
> > } else {
> > $query = "UPDATE `table` SET `hits` = '$count', `agent` =
> > '$agent', `ts` = '$date_time' WHERE `page` = '$page'";
> > $result = mysql_query($query) or die ('Error! -- ' .
> > mysql_error());
> > }
> >
> > However, I've read where this is not really acceptable. Can
> > someone help me eliminate the 'else' portion of this if statement?
> >
> > Thank you,
> > Angela
> >
> > P.S. I realize the above isn't complete code but it should still be
> > clear. If not, let me know.
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
What about this:
if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip)
and ($current_dt < ($saved_dt + 3600)) ) )
The 3 sub-expressions are grouped with an extra set of brackets and
the ! inverts the whole thing, so no need for an else clause.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 11-3-2013 22:32, Angela Barone wrote:
I'm looking for an 'unless' statement, but as far as I can tell, PHP
doesn't have one. Hopefully someone can help me rewrite my statement.
In English, I want to say: "always do something UNLESS these 3 conditions
are met".
The best I've been able to come up with in PHP is this:
if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
($current_dt < ($saved_dt + 3600)) ) {
return;
} else {
$query = "UPDATE `table` SET `hits` = '$count', `agent` = '$agent', `ts` =
'$date_time' WHERE `page` = '$page'";
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
}
However, I've read where this is not really acceptable. Can someone
help me eliminate the 'else' portion of this if statement?
Thank you,
Angela
P.S. I realize the above isn't complete code but it should still be clear. If
not, let me know.
Logically, unless means the same as if not. As long as you condense
your entire expression to a single boolean result, the only thing you
would need to do is negate it to create your unless-statement.
In code, this would mean:
unless ( $a )
=
if ( !$a )
or to show it in a more clear way:
unless ( $a and $b )
=
if ( ! ($a and $b) )
So in simple terms, just stick a ! (or the keyword not) in front of your
expression, and you'll have exactly what you want:
if( not ( ($current_page == $saved_page) and ($current_ip == $saved_ip)
and ($current_dt < ($saved_dt + 3600) ) ) {
--- End Message ---
--- Begin Message ---
On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote:
> Since you already have the return statement with the if statement the else
> isn't required. If those three statements are true you would exit the call
> any ways
I don't follow. The else contains the meat of the statement.
Angela
--- End Message ---
--- Begin Message ---
What you have
if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
($current_dt < ($saved_dt + 3600)) ) {
return;
} else {
$query = "UPDATE `table` SET `hits` = '$count', `agent` =
'$agent', `ts` = '$date_time' WHERE `page` = '$page'";
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
}
is the same as writing it as
if ( ($current_page == $saved_page) && ($current_ip == $saved_ip) &&
($current_dt < ($saved_dt + 3600)) ) {
return;
}
$query = "UPDATE `table` SET `hits` = '$count', `agent` = '$agent', `ts` =
'$date_time' WHERE `page` = '$page'";
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
On Mon, Mar 11, 2013 at 5:48 PM, Angela Barone
<ang...@italian-getaways.com>wrote:
> On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote:
>
> Since you already have the return statement with the if statement the else
> isn't required. If those three statements are true you would exit the call
> any ways
>
>
> I don't follow. The else contains the meat of the statement.
>
> Angela
>
--- End Message ---
--- Begin Message ---
On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote:
> if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
> ($current_dt < ($saved_dt + 3600)) ) )
Hello Ash,
This makes sense to me, but I can't get it to work, so I'm either not
understanding it or I'm asking the wrong question. Here's a complete scriptlet:
<?php
$saved_page = 'ddd';
$page = 'ddd';
$saved_ip = '1.1.1.1';
$ip = '1.1.1.1';
$saved_dt = '2013-03-11 11:11:11';
$current_dt = '2013-03-11 11:22:11';
if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
($current_dt < ($saved_dt + 3600)) ) ) {
echo 'Save results.';
} else {
echo "Don't save.";
}
?>
Using the supplied data, the result should be "Don't save." Can you
see what's wrong?
Angela
--- End Message ---
--- Begin Message ---
Angela,
the variable $current_page does not exist. so $curent_page does not equal
$saved_page. Also the ! in front of the entire statement means that all of
this is false. Since one items is true and not true = false "Don't save"
is echoed out.
If you are looking to save the results based on the above sample it would
look like
if(($page === $saved_page) && ($current_ip === $saved_ip) && ($current_dt <
($saved_dt +3600)) {
//save the results
} else {
//don't save
}
I would also suggest keeping with your original statement to return early
and return often. Its best to exit out of your functions sooner than later.
Specially if its a large function.
On Mon, Mar 11, 2013 at 6:03 PM, Angela Barone
<ang...@italian-getaways.com>wrote:
> On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote:
> > if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip)
> and ($current_dt < ($saved_dt + 3600)) ) )
>
> Hello Ash,
>
> This makes sense to me, but I can't get it to work, so I'm either
> not understanding it or I'm asking the wrong question. Here's a complete
> scriptlet:
>
> <?php
> $saved_page = 'ddd';
> $page = 'ddd';
> $saved_ip = '1.1.1.1';
> $ip = '1.1.1.1';
> $saved_dt = '2013-03-11 11:11:11';
> $current_dt = '2013-03-11 11:22:11';
>
> if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
> ($current_dt < ($saved_dt + 3600)) ) ) {
> echo 'Save results.';
> } else {
> echo "Don't save.";
> }
> ?>
>
> Using the supplied data, the result should be "Don't save." Can
> you see what's wrong?
>
> Angela
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:
> the variable $current_page does not exist.
That was my problem. :( I've been staring at this for too long. Too
bad there's not a 'use strict' pragma.
> I would also suggest keeping with your original statement to return early and
> return often. Its best to exit out of your functions sooner than later.
> Specially if its a large function.
O.K. I just thought there might be a more elegant way of doing it. I
at least got rid of the else statement like you mentioned.
Thanks for your help,
Angela
--- End Message ---
--- Begin Message ---
On 3/11/13 6:25 PM, Angela Barone wrote:
On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:
the variable $current_page does not exist.
That was my problem. :( I've been staring at this for too long. Too
bad there's not a 'use strict' pragma.
There is. Always set your development environment to E_ALL | E_STRICT,
and it will yell at you about every little thing, including undefined
variables.
http://php.net/manual/en/function.error-reporting.php
I would also suggest keeping with your original statement to return early and
return often. Its best to exit out of your functions sooner than later.
Specially if its a large function.
O.K. I just thought there might be a more elegant way of doing it. I
at least got rid of the else statement like you mentioned.
Thanks for your help,
Angela
If you find yourself with a function that's too long and complex from
the if-statements, your first step is to break it up into utility functions.
if (...) {
// Something Long
}
else {
// Something Else Long
}
Becomes:
if (...) {
something_long();
}
else {
something_else_long();
}
function something_long() {
}
function something_else_long() {
}
That helps both readability and testability.
Also, on your original boolean question, note that negation is
distributive. That is:
!($a && $b && $c)
is the same as:
!$a || !$b || $!c
Which means that if your checks are all equality checks, as in your
case, you can simply do:
if ($a != 'a' || $b != 'b' || $c >= 'c') {
}
Which may be easier to read. If those checks are not trivial then
there's also a micro-performance benefit there, as the first statement
that evaluates to true will cause the whole thing to return true, so the
second and third options don't need to be evaluated.
--Larry Garfield
--- End Message ---