php-general Digest 12 Jul 2007 13:29:17 -0000 Issue 4899

Topics (messages 258664 through 258688):

Re: PHP list as a blog
        258664 by: Robert Cummings

Re: Checking Post Data against DB Data
        258665 by: Chris

getting the "next" element of an associative array
        258666 by: Olav Mørkrid
        258667 by: Man-wai Chang
        258668 by: Chris
        258669 by: Jim Lucas
        258670 by: Olav Mørkrid
        258671 by: Chris
        258672 by: Olav Mørkrid

Array Push question
        258673 by: John Comerford
        258674 by: dev.lenss.nl
        258676 by: Stut
        258677 by: dev.lenss.nl
        258678 by: Zoltán Németh
        258679 by: Stut
        258681 by: M. Sokolewicz
        258684 by: Stut

Re: Array Question
        258675 by: Stut

Re: PHP Brain Teasers
        258680 by: Jay Blanchard

Single Quote in String functions
        258682 by: Sancar Saran
        258683 by: M. Sokolewicz
        258685 by: Stut
        258687 by: Sancar Saran
        258688 by: Sancar Saran

need a form for connecting to paypal payment pro.
        258686 by: Ross

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 ---
On Wed, 2007-07-11 at 17:51 -0500, Richard Lynch wrote:
> On Wed, June 13, 2007 3:04 pm, Robert Cummings wrote:
> 
> > But you might not. It depends on what you decide to include() instead
> > of
> > redirecting. I guess in the included source you could code aorund not
> > having the correct URL parameters and default to something sensible,
> > but
> > that still doesn't address the content/request mismatch.
> 
> Bought a house, and I've been away from the list, so I'm resurrecting
> this only to point out...
> 
> As far as I'm concerned, if it requires a login to see X, and you ask
> for X and aren't logged in, seeing the login page with the URL X *IS*
> the perfectly valid answer for what you should see.
> 
> If I needed Google to index my content that requires a login, then I
> don't need a login because that's just a plain silly setup...
> 
> Google's gonna have a bunch of pages that users can't see unless they
> login?
> 
> Then it's not a login;  It's a scam to collect a bunch of user data.
> 
> :-) :-) :-)
> 
> PS
> And I could just look at the Google User Agent and not require login
> for that, which anybody could forge, but so what?  They'll get the
> same damn info by knowing what to search for in Google anyway, if I'm
> giving Google the content without a login.

I guess what you're suggesting is a lot like using a relative URL in a
redirect... it works, it saves some time, but it's not quite right ;)

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
kvigor wrote:
OK Chris,

I understand that we're checking checking the form data and escaping it, but can explain what's going on in the WHERE clause and 1=1 tad bit more.

Instead of looking at all records in your original attempt (which will work fine for 10 records), you limit what you are looking at (which works a lot better for 50,000 records).

The 1=1 is something that the database will remove internally but basically it stops an invalid query:

select * from table where a='b' and c='d' and

That's why I said you can either remove the last and:

select * from table where a='b' and c='d'

or

add 1=1:

select * from table where a='b' and c='d' and 1=1

They work out the same.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
let's say we have the following associative array:

$array = array(
 "red" => "ferrari",
 "yellow" => "volkswagen",
 "green" => "mercedes",
 "blue" => "volvo"
);

then we have a current index into the array:

$index = "yellow";
$current = $array[$index];

now: how do i get the key of the next array element (in this case "green")?

$next = ?

--- End Message ---
--- Begin Message ---
let's say we have the following associative array:
$array = array(
 "red" => "ferrari",
 "yellow" => "volkswagen",
 "green" => "mercedes",
 "blue" => "volvo"
);
now: how do i get the key of the next array element (in this case "green")?
$next = ?

Why not define your array with number index as well in the first place?

--
  .~.   Might. Courage. Vision. Sincerity. http://www.linux-sxs.org
 / v \  Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Fedora Core 4)  Linux 2.6.17-1.2142_FC4
  ^ ^   14:26:01 up 160 days 22:10 2 users load average: 0.00 0.02 0.00

--- End Message ---
--- Begin Message ---
Olav Mørkrid wrote:
let's say we have the following associative array:

$array = array(
 "red" => "ferrari",
 "yellow" => "volkswagen",
 "green" => "mercedes",
 "blue" => "volvo"
);

then we have a current index into the array:

$index = "yellow";
$current = $array[$index];

now: how do i get the key of the next array element (in this case "green")?

$next = ?

Funnily enough:

$next = next($array);

http://www.php.net/manual/en/function.next.php


--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Olav Mørkrid wrote:
let's say we have the following associative array:

$array = array(
 "red" => "ferrari",
 "yellow" => "volkswagen",
 "green" => "mercedes",
 "blue" => "volvo"
);

then we have a current index into the array:

$index = "yellow";
$current = $array[$index];

now: how do i get the key of the next array element (in this case "green")?

$next = ?

Give this a shot

<?php

function array_next($ar, $curr) {
        $capture = false;
        $next = '';
        foreach ( $ar AS $k => $v ) {
                if ( $capture ) {
                        return array($k => $v);
                }
                if ( $k == $curr ) {
                        $capture = true;
                }
        }
        return $next;
}


$array = array(
 "red" => "ferrari",
 "yellow" => "volkswagen",
 "green" => "mercedes",
 "blue" => "volvo"
);

print_r( array_next($array, 'yellow') );

--- End Message ---
--- Begin Message ---
chris

for your suggestion to work, the internal array pointer of $array
would first have to be set to point to the current element ($index).

but how do you do this?

this may seem like childs play, but i actually can't find any
documented php function for this. it would be something like:

array_set_internal_pointer($array, $index);

On 12/07/07, Chris <[EMAIL PROTECTED]> wrote:
Olav Mørkrid wrote:
> let's say we have the following associative array:
>
> $array = array(
>  "red" => "ferrari",
>  "yellow" => "volkswagen",
>  "green" => "mercedes",
>  "blue" => "volvo"
> );
>
> then we have a current index into the array:
>
> $index = "yellow";
> $current = $array[$index];
>
> now: how do i get the key of the next array element (in this case "green")?
>
> $next = ?

Funnily enough:

$next = next($array);

http://www.php.net/manual/en/function.next.php


--
Postgresql & php tutorials
http://www.designmagick.com/


--- End Message ---
--- Begin Message ---
Olav Mørkrid wrote:
chris

for your suggestion to work, the internal array pointer of $array
would first have to be set to point to the current element ($index).

but how do you do this?

this may seem like childs play, but i actually can't find any
documented php function for this. it would be something like:

My apologies - I misread your post. I just thought you wanted the next record, not the next key.

Jim's function looked pretty easy and simple :)

On 12/07/07, Chris <[EMAIL PROTECTED]> wrote:
Olav Mørkrid wrote:
> let's say we have the following associative array:
>
> $array = array(
>  "red" => "ferrari",
>  "yellow" => "volkswagen",
>  "green" => "mercedes",
>  "blue" => "volvo"
> );
>
> then we have a current index into the array:
>
> $index = "yellow";
> $current = $array[$index];
>
> now: how do i get the key of the next array element (in this case "green")?
>
> $next = ?

Funnily enough:

$next = next($array);

http://www.php.net/manual/en/function.next.php


--
Postgresql & php tutorials
http://www.designmagick.com/




--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
yep, a for loop is the fallback i use now.

any reason why there isn't a built-in function for this?

any plans for it in future versions of php?

--- End Message ---
--- Begin Message ---
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

Specifically I am wonder if I can avoid having to use 'count'.

TIA,
 JC

--- End Message ---
--- Begin Message ---
On Thu, 12 Jul 2007 18:45:36 +1000, John Comerford <[EMAIL PROTECTED]> wrote:
> Hi Folks,
> 
> Is there a better way of doing the following:
> 
> $Rows[] = array();
> $currentRow = count($Rows) - 1;
> $Rows[$currentRow]['test'] = "this is a test";
> 
> Specifically I am wonder if I can avoid having to use 'count'.
> 
> TIA,
>   JC
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

This code looks weird...

$currenRow will be numeric. So why would you do $currentRow['test']?
Anyway if you just wanna add an element to the end of the array use array_push

http://nl3.php.net/manual/en/function.array-push.php

--- End Message ---
--- Begin Message ---
John Comerford wrote:
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

Specifically I am wonder if I can avoid having to use 'count'.

1) The code above will produce a $currentRow of -1 which is probably not what you want.

2) If you actually mean that you have an array that contains items and you want the last one, used end (http://php.net/end).

3) I'm not really sure what the context is, but this is a very odd way of working with arrays. Either you already know the key or you don't. If you're just trying to append to the array you can do that with the following syntax... $Rows[] = array('test' => 'this is a test');

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Thu, 12 Jul 2007 18:45:36 +1000, John Comerford <[EMAIL PROTECTED]> wrote:
> Hi Folks,
> 
> Is there a better way of doing the following:
> 
> $Rows[] = array();
> $currentRow = count($Rows) - 1;
> $Rows[$currentRow]['test'] = "this is a test";
> 
> Specifically I am wonder if I can avoid having to use 'count'.
> 
> TIA,
>   JC
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Seems my eyes are to tired today. Didn't read the code very good.
But the answer still stays the same :)

$Rows = array();
array_push($Rows, array('test' => 'this is a test'));

--- End Message ---
--- Begin Message ---
2007. 07. 12, csütörtök keltezéssel 10.28-kor Stut ezt írta:
> John Comerford wrote:
> > Hi Folks,
> > 
> > Is there a better way of doing the following:
> > 
> > $Rows[] = array();
> > $currentRow = count($Rows) - 1;
> > $Rows[$currentRow]['test'] = "this is a test";
> > 
> > Specifically I am wonder if I can avoid having to use 'count'.
> 
> 1) The code above will produce a $currentRow of -1 which is probably not 
> what you want.

Maybe you didn't notice the [] in the first line of the OP's code?
I think this code should produce 0 for $currentRow, not -1.

greets
Zoltán Németh

> 
> 2) If you actually mean that you have an array that contains items and 
> you want the last one, used end (http://php.net/end).
> 
> 3) I'm not really sure what the context is, but this is a very odd way 
> of working with arrays. Either you already know the key or you don't. If 
> you're just trying to append to the array you can do that with the 
> following syntax... $Rows[] = array('test' => 'this is a test');
> 
> -Stut
> 
> -- 
> http://stut.net/
> 

--- End Message ---
--- Begin Message ---
Zoltán Németh wrote:
2007. 07. 12, csütörtök keltezéssel 10.28-kor Stut ezt írta:
John Comerford wrote:
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

Specifically I am wonder if I can avoid having to use 'count'.
1) The code above will produce a $currentRow of -1 which is probably not what you want.

Maybe you didn't notice the [] in the first line of the OP's code?
I think this code should produce 0 for $currentRow, not -1.

Indeed, my bad. In that case the OP is better off creating the item in a temporary variable and then adding it to the array.

$row = array();
$row['test'] = 'this is a test';
$Rows[] = $row;

-Stut

--
http://stut.net/

2) If you actually mean that you have an array that contains items and you want the last one, used end (http://php.net/end).

3) I'm not really sure what the context is, but this is a very odd way of working with arrays. Either you already know the key or you don't. If you're just trying to append to the array you can do that with the following syntax... $Rows[] = array('test' => 'this is a test');

-Stut

--
http://stut.net/



--- End Message ---
--- Begin Message ---
Stut wrote:
Zoltán Németh wrote:
2007. 07. 12, csütörtök keltezéssel 10.28-kor Stut ezt írta:
John Comerford wrote:
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

Specifically I am wonder if I can avoid having to use 'count'.
1) The code above will produce a $currentRow of -1 which is probably not what you want.

Maybe you didn't notice the [] in the first line of the OP's code?
I think this code should produce 0 for $currentRow, not -1.

Indeed, my bad. In that case the OP is better off creating the item in a temporary variable and then adding it to the array.

$row = array();
$row['test'] = 'this is a test';
$Rows[] = $row;

-Stut

what's wrong with skipping the temporary variable and just doing
$Rows[] = array('test'=>'this is a test');
?

--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
Stut wrote:
Zoltán Németh wrote:
2007. 07. 12, csütörtök keltezéssel 10.28-kor Stut ezt írta:
John Comerford wrote:
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

Specifically I am wonder if I can avoid having to use 'count'.
1) The code above will produce a $currentRow of -1 which is probably not what you want.

Maybe you didn't notice the [] in the first line of the OP's code?
I think this code should produce 0 for $currentRow, not -1.

Indeed, my bad. In that case the OP is better off creating the item in a temporary variable and then adding it to the array.

$row = array();
$row['test'] = 'this is a test';
$Rows[] = $row;

-Stut

what's wrong with skipping the temporary variable and just doing
$Rows[] = array('test'=>'this is a test');
?

Nothing, unless you're building a complex element. I was assuming that the OP had simplified their code down to the minimum required to illustrate the problem.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
On Wed, July 11, 2007 4:16 pm, Robert Cummings wrote:
But I'd have to say that the intent is not all that clear, really,
and
I'd be leery of this feature, personally.
I wouldn't be leery at all. It's been around for a very long time and
it's documented:


http://www.php.net/manual/en/language.types.array.php#language.types.array.casting

As soon as I hit send I knew that would be mis-interpreted...

Leery is the wrong word.

Sorry.

It just seems a bit to clever to me...

I suspect I'd skim this code a hundred times and not realize what it
was doing.

But maybe that's just me. :-)

I would have to agree. I'm a big fan of self-documenting code, and this one requires a little bit more knowledge of the intricacies of PHP than I would expect from your 'average' developer.

If performance is going to be an issue (and in terms of cycles I can't see this saving much), buy faster/more hardware - it's far cheaper than developer time!!

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
[snip]
Mine was trying to go for an old funk song that starts:

What goes up, must come down.
Spinning wheel got to go 'round
Drop all the painted ponies by the riverside.
[mumble] let the spinning wheel slide.

Only later did I realize I broke the cardinal rule of Name That Tune
and have NO IDEA what the song title is nor who wrote/sang it...
[/snip]

Spinning Wheel - Blood, Sweat & Tears

--- End Message ---
--- Begin Message ---
Hi,

I cannot do any operation wiht single quote like

explode("'",$strContent);

Did I miss someting ?

Regards

Sancar

--- End Message ---
--- Begin Message ---
Sancar Saran wrote:
Hi,

I cannot do any operation wiht single quote like

explode("'",$strContent);

Did I miss someting ?

Regards

Sancar

what do you mean by 'cannot do' ?

If I do:
<?php
$string = "part1 ' part2";
print_r(explode("'", $string));

it will return
Array(
   [0] = "part1 "
   [1] = " part2"
)

--- End Message ---
--- Begin Message ---
Sancar Saran wrote:
I cannot do any operation wiht single quote like

explode("'",$strContent);

Did I miss someting ?

In what way "can't"? What happens / doesn't happen?

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Thursday 12 July 2007 15:11:28 Stut wrote:
> Sancar Saran wrote:
> > I cannot do any operation wiht single quote like
> >
> > explode("'",$strContent);
> >
> > Did I miss someting ?
>
> In what way "can't"? What happens / doesn't happen?
>
> -Stut
>
> --
> http://stut.net/

Hi,

Problem was

$strng = "'cInputI' style='width:146px;'>";
$arrExplode = explode("'",$string);

$arrExplode contins

[array][1]
    * "0"=>[string]['cInputI' style='width:146px;'>]

And not only explode for example I canot trim first "'" 

Regards

Sancar

--- End Message ---
--- Begin Message ---
On Thursday 12 July 2007 15:11:28 Stut wrote:
> Sancar Saran wrote:
> > I cannot do any operation wiht single quote like
> >
> > explode("'",$strContent);
> >
> > Did I miss someting ?
>
Omg, It's my bad, sorry for lameness. 

Before the exploding text I do some encoding decodings. 

So? I do mis sequenced decodings. Thats why it does not work explode or trim, 
or str_replace even all other string functions.

Regards

Sancar

--- End Message ---
--- Begin Message ---
Hi,

I need a secure form. I have one here 
http://www.edinburghnights.co.uk/pay/php/curl_https.html but it has no 
algorithm check on the CC number. Also I need to make the form secure. Can 
someone point me to an example or tutorial.


Many thanks,


R. 

--- End Message ---

Reply via email to