php-general Digest 15 Mar 2011 09:39:59 -0000 Issue 7227
Topics (messages 311837 through 311857):
Re: Deleting elements from the middle of an array
311837 by: Peter Lind
311838 by: Marc Guay
311839 by: Jim Lucas
311840 by: Paul M Foster
311841 by: Peter Lind
311842 by: Marc Guay
311847 by: Curtis Maurand
311849 by: Paul M Foster
311855 by: Peter Lind
php or juvascript convert IETF format to ISO08601
311843 by: Jordan
311844 by: Simon J Welsh
311857 by: Simon J Welsh
Re: Handling exit in eval
311845 by: DELiTH
help with a safe mode snag
311846 by: Jack
Failure in bitwise operations moving from 5.2.x to 5.3.x
311848 by: Andy McKenzie
311850 by: Adam Richardson
problem with if and exact match
311851 by: Jack
311852 by: Admin
311853 by: Simon J Welsh
311854 by: Jack
311856 by: FeIn
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 14 March 2011 21:31, Paul M Foster <[email protected]> wrote:
> Here's what I need to do: I have an indexed array, from which I need to
> delete elements in the middle. Once completed, the indexes should be
> numerically in sequence, as they were when I first encountered the
> array. That is:
>
> Before:
> $arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
>
> After:
> $arr = array(0 => 5, 1 => 6, 2 => 9, 3 => 10);
>
>
> I've tried:
>
> 1) Using for() with unset(). Elements are deleted, but the indexes are
> no longer sequential.
>
> 2) Using for() with array_splice(). Understandably, deletes certain
> elements but not others.
>
> 3) Using foreach() with referenced array elements. Neither unset() nor
> array_splice() appear to have any effect on the array at all.
>
> 4) while() loop using current() and the like. But these array functions
> return values, not references, so the array isn't actually modified.
>
> 5) array_walk() with unset() array_splice(). No effect on the array.
>
> Anyone know how to do this, or know of a reference on how to?
>
Remove the elements, then use sort().
Regards
Peter
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
> Here's what I need to do: I have an indexed array, from which I need to
> delete elements in the middle. Once completed, the indexes should be
> numerically in sequence, as they were when I first encountered the
> array.
I believe that array_values() will do the trick.
Marc
--- End Message ---
--- Begin Message ---
On 3/14/2011 1:31 PM, Paul M Foster wrote:
> Here's what I need to do: I have an indexed array, from which I need to
> delete elements in the middle. Once completed, the indexes should be
> numerically in sequence, as they were when I first encountered the
> array. That is:
>
> Before:
> $arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
>
> After:
> $arr = array(0 => 5, 1 => 6, 2 => 9, 3 => 10);
>
>
> I've tried:
>
> 1) Using for() with unset(). Elements are deleted, but the indexes are
> no longer sequential.
>
> 2) Using for() with array_splice(). Understandably, deletes certain
> elements but not others.
>
> 3) Using foreach() with referenced array elements. Neither unset() nor
> array_splice() appear to have any effect on the array at all.
>
> 4) while() loop using current() and the like. But these array functions
> return values, not references, so the array isn't actually modified.
>
> 5) array_walk() with unset() array_splice(). No effect on the array.
>
> Anyone know how to do this, or know of a reference on how to?
>
> Paul
>
<?php
# Setup match array
$match_these = array(7,8);
# Setup data array
$arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
# Loop data array
foreach ( $arr AS $k => $v )
{
# Simple matching this may be, but work yes it does
if ( in_array($v, $match_these) )
{
# Remove matched items
unset($arr[$k]);
}
}
# Reset array indexes
$arr = array_values($arr);
# Print it
print_r($arr);
# $arr will now be array(0 => 5, 1 => 6, 2 => 9, 3 => 10);
?>
--- End Message ---
--- Begin Message ---
On Mon, Mar 14, 2011 at 09:34:33PM +0100, Peter Lind wrote:
> On 14 March 2011 21:31, Paul M Foster <[email protected]> wrote:
> > Here's what I need to do: I have an indexed array, from which I need to
> > delete elements in the middle. Once completed, the indexes should be
> > numerically in sequence, as they were when I first encountered the
> > array. That is:
> >
> > Before:
> > $arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
> >
> > After:
> > $arr = array(0 => 5, 1 => 6, 2 => 9, 3 => 10);
> >
> >
> > I've tried:
> >
> > 1) Using for() with unset(). Elements are deleted, but the indexes are
> > no longer sequential.
> >
> > 2) Using for() with array_splice(). Understandably, deletes certain
> > elements but not others.
> >
> > 3) Using foreach() with referenced array elements. Neither unset() nor
> > array_splice() appear to have any effect on the array at all.
> >
> > 4) while() loop using current() and the like. But these array functions
> > return values, not references, so the array isn't actually modified.
> >
> > 5) array_walk() with unset() array_splice(). No effect on the array.
> >
> > Anyone know how to do this, or know of a reference on how to?
> >
>
> Remove the elements, then use sort().
I've given a simplified example. The actual target array is
multi-dimensional. Sort() won't work in a case like that, as far as I
know. Moreover, I don't want the array sorted based on the element
values.
Paul
--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com
--- End Message ---
--- Begin Message ---
On 14 March 2011 22:10, Paul M Foster <[email protected]> wrote:
> On Mon, Mar 14, 2011 at 09:34:33PM +0100, Peter Lind wrote:
>
>> On 14 March 2011 21:31, Paul M Foster <[email protected]> wrote:
>> > Here's what I need to do: I have an indexed array, from which I need to
>> > delete elements in the middle. Once completed, the indexes should be
>> > numerically in sequence, as they were when I first encountered the
>> > array. That is:
>> >
>> > Before:
>> > $arr = array(0 => 5, 1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
>> >
>> > After:
>> > $arr = array(0 => 5, 1 => 6, 2 => 9, 3 => 10);
>> >
>> >
>> > I've tried:
>> >
>> > 1) Using for() with unset(). Elements are deleted, but the indexes are
>> > no longer sequential.
>> >
>> > 2) Using for() with array_splice(). Understandably, deletes certain
>> > elements but not others.
>> >
>> > 3) Using foreach() with referenced array elements. Neither unset() nor
>> > array_splice() appear to have any effect on the array at all.
>> >
>> > 4) while() loop using current() and the like. But these array functions
>> > return values, not references, so the array isn't actually modified.
>> >
>> > 5) array_walk() with unset() array_splice(). No effect on the array.
>> >
>> > Anyone know how to do this, or know of a reference on how to?
>> >
>>
>> Remove the elements, then use sort().
>
> I've given a simplified example. The actual target array is
> multi-dimensional. Sort() won't work in a case like that, as far as I
> know. Moreover, I don't want the array sorted based on the element
> values.
Ahh, I see - you wanted me to guess at the actual circumstances of the
case instead of provide an answer to the example you posted. My bad.
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
> I've given a simplified example. The actual target array is
> multi-dimensional.
Your questioni sn't entirely clear but there's lot of chatter about
multidimensional arrays on the array_values() page that might provide
a solution.
--- End Message ---
--- Begin Message ---
how about creating two arrays, one empty one.
pop the elements
you want out of the first array and push them to the second. skip
the push on the elements you don't want in the second array?
Just a thought.
--curtis
Paul M Foster wrote:
> On Mon, Mar 14, 2011 at 09:34:33PM +0100, Peter Lind wrote:
>
>> On 14 March 2011 21:31, Paul M Foster
<[email protected]> wrote:
>> > Here's what I
need to do: I have an indexed array, from which I need
>> to
>> > delete elements in the middle. Once completed, the indexes
should be
>> > numerically in sequence, as they were when I
first encountered the
>> > array. That is:
>>
>
>> > Before:
>> > $arr = array(0 => 5,
1 => 6, 2 => 7, 3 => 8, 4 => 9, 5 => 10);
>>
>
>> > After:
>> > $arr = array(0 => 5,
1 => 6, 2 => 9, 3 => 10);
>> >
>>
>
>> > I've tried:
>> >
>> >
1) Using for() with unset(). Elements are deleted, but the indexes are
>> > no longer sequential.
>> >
>>
> 2) Using for() with array_splice(). Understandably, deletes
certain
>> > elements but not others.
>> >
>> > 3) Using foreach() with referenced array elements. Neither
unset() nor
>> > array_splice() appear to have any effect on
the array at all.
>> >
>> > 4) while() loop
using current() and the like. But these array
>> functions
>> > return values, not references, so the array isn't actually
modified.
>> >
>> > 5) array_walk() with
unset() array_splice(). No effect on the array.
>> >
>> > Anyone know how to do this, or know of a reference on how
to?
>> >
>>
>> Remove the elements,
then use sort().
>
> I've given a simplified example. The
actual target array is
> multi-dimensional. Sort() won't work in a
case like that, as far as I
> know. Moreover, I don't want the
array sorted based on the element
> values.
>
>
Paul
>
> --
> Paul M. Foster
>
http://noferblatz.com
> http://quillandmouse.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:
> On 14 March 2011 22:10, Paul M Foster <[email protected]> wrote:
[snip]
> >> Remove the elements, then use sort().
> >
> > I've given a simplified example. The actual target array is
> > multi-dimensional. Sort() won't work in a case like that, as far as I
> > know. Moreover, I don't want the array sorted based on the element
> > values.
>
> Ahh, I see - you wanted me to guess at the actual circumstances of the
> case instead of provide an answer to the example you posted. My bad.
Is the sarcasm really necessary?
Paul
--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com
--- End Message ---
--- Begin Message ---
On Mar 15, 2011 4:10 AM, "Paul M Foster" <[email protected]> wrote:
>
> On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:
>
> > On 14 March 2011 22:10, Paul M Foster <[email protected]> wrote:
>
> [snip]
>
> > >> Remove the elements, then use sort().
> > >
> > > I've given a simplified example. The actual target array is
> > > multi-dimensional. Sort() won't work in a case like that, as far as I
> > > know. Moreover, I don't want the array sorted based on the element
> > > values.
> >
> > Ahh, I see - you wanted me to guess at the actual circumstances of the
> > case instead of provide an answer to the example you posted. My bad.
>
> Is the sarcasm really necessary?
>
Without it, would you learn to post the actual details instead of something
irrelevant? If yes, then my apologies.
Regards
--- End Message ---
--- Begin Message ---
Hello Evrybody,
Can i convert IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") in
ISO8601 format (ex: "2009-11-05T13:15:30Z")
Does somebody know some php scripte or similar?
Thanks...
--- End Message ---
--- Begin Message ---
On 15/03/2011, at 12:32 PM, Jordan wrote:
> Hello Evrybody,
>
> Can i convert IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") in ISO8601
> format (ex: "2009-11-05T13:15:30Z")
>
> Does somebody know some php scripte or similar?
>
> Thanks...
strtotime() (http://php.net/strtotime) and date() (http://php.net/date).
There's even a DATE_ISO8601 constant for the correct date format.
---
Simon Welsh
Admin of http://simon.geek.nz/
Who said Microsoft never created a bug-free program? The blue screen never,
ever crashes!
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
--- End Message ---
--- Begin Message ---
On 15/03/2011, at 9:18 PM, Joce Jovanov wrote:
> On Tue, Mar 15, 2011 at 12:44 AM, Simon J Welsh <[email protected]> wrote:
>
>> On 15/03/2011, at 12:32 PM, Jordan wrote:
>>
>>> Hello Evrybody,
>>>
>>> Can i convert IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST") in
>> ISO8601 format (ex: "2009-11-05T13:15:30Z")
>>>
>>> Does somebody know some php scripte or similar?
>>>
>>> Thanks...
>>
>> strtotime() (http://php.net/strtotime) and date() (http://php.net/date).
>> There's even a DATE_ISO8601 constant for the correct date format.
>>
>> ---
>> Simon Welsh
>> Admin of http://simon.geek.nz/
>>
>> Who said Microsoft never created a bug-free program? The blue screen never,
>> ever crashes!
>>
>> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
>>
>>
> Hi again,
> Thanks for the email,
> do you alredy know some function who will convert IETF format to ISO8601
You'd use the strtotime function to convert the IETF format to a timestamp,
then then date function to convert that timestamp to ISO8601.
Something like date(DATE_ISO8601, strtotime('IETF format string')).
---
Simon Welsh
Admin of http://simon.geek.nz/
Who said Microsoft never created a bug-free program? The blue screen never,
ever crashes!
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
--- End Message ---
--- Begin Message ---
Richard Quadling wrote:
> On 14 March 2011 12:14, DELiTH <[email protected]> wrote:
>> Richard Quadling wrote:
>>
>>> 2011/3/14 Richard Quadling <[email protected]>:
>>>
>>> And where is my UNDO button.
>>>
>>> Essentially, having exit in the eval code is no different to having it
>>> in non-eval code. eval isn't a separate entity which can be
>>> terminated.
>>>
>>> So, code the eval code differently.
>>>
>>> If you can provide some examples, maybe we can come up with a better
>>> solution.
>>>
>>>
>>>
>>
>> I'm developing a kind of sandbox where you will be able to run a script
>> without affecting your current context. The script is loaded and parsed
>> which gives me the opportunity to allow or deny functions and classes
>> used in the script.
>> The only problem I have so far is the exit function which, it if is
>> allowed, terminates the calling script as well as the eval'ed script.
>>
>> By using a return the problem is solved as long as the user doesn't
>> write a function containing an exit.
>>
>> Here is a simple script thet the user might write (probably as useful as
>> a "Hello, world!".
>>
>> <?php
>> function DoSomethingOrExit($test) {
>> if($test == 1) {
>> exit;
>> }
>> return;
>> }
>>
>> DoSomethingOrExit(0);
>> echo "Hello";
>> DoSomethingOrExit(1);
>> echo ", world!";
>> exit;
>> echo "Bye";
>> ?>
>>
>> By replacing exit with return this code will echo "Hello, world!" before
>> returning without echoing "Bye".
>>
>>
>> Another perfect solution would be if there was a way to trigger an error
>> within the eval'ed script that "crashes" it and returns to the calling
>> script. But then it just comes back to the entity-problem as you pointed
>> out.
>>
>>
>> /Thomas
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Why not just invoke a separate instance of PHP using exec() ?
>
> Or take a look at runkit/runkit_Sandbox :
> http://uk.php.net/manual/en/book.runkit.php
>
exec() tends to allocate to much resources and Runkit_Sandbox is what
I'm trying to get away from =)
The Runkit_Sandbox requires that the server is configured to use it and
my intended solution will run on almost any server without any spcial
needs. (exec is also restricted from many hosting server which makes it
a poor choise.)
My little SandBox will run on almost any server and doesn't require any
special configuration. Sure, it will suck on resources but it will work
as an alternative =)
/Thomas
--- End Message ---
--- Begin Message ---
Hello All,
Im writing a script that creates a temp file which it then encrypts and
sends out in an email.
This works 100% on servers that don't have safe mode, but this server with
safe mode doesn't understand it's all the same user.
Error:
Mon Mar 14 21:10:11 2011] [error] [client 14.18.8.43] PHP Warning: fopen()
[<a href='function.fopen'>function.fopen</a>]: SAFE MODE Restriction in
effect. The script whose uid is 50069 is not allowed to access
/tmp/A1_mYM5q5 owned by uid 48 in
Any suggestions?
Thanks!
--- End Message ---
--- Begin Message ---
Greetings,
I'm moving some scripts from an older server (SuSE who-knows-what,
running PHP 5.2.5) to a newer one (Ubuntu 10.10, running PHP 5.3.2).
For the most part there haven't been any problems, or they've been
things that I was able to fix easily. This one's got me stumped. I
have the following line in a script:
$this->bc = ($this->network | (~$this->netmask)) & 4294967295;
$this->network and $this->netmask should both be of type long, and I
should wind up with another long. I didn't write the original method,
and I can't remember what "bc" stands for at the moment, but it's part
of a tool for working out first and last IP address, netmask, and a
few other things from a subnet definition.
On the old system, it works fine. On the new system, I get the following error:
"PHP Fatal error: Unsupported operand types in
/var/www/test/common_subnet.inc on line 39"
I've done a little searching without any luck: if anyone can give me
a quick answer, or at least point me to something that will explain
what's going on, I'd appreciate it.
Thanks,
Alex McKenzie
--- End Message ---
--- Begin Message ---
>
> This one's got me stumped. I
> have the following line in a script:
>
> $this->bc = ($this->network | (~$this->netmask)) & 4294967295;
>
> $this->network and $this->netmask should both be of type long, and I
> should wind up with another long. I didn't write the original method,
> and I can't remember what "bc" stands for at the moment, but it's part
> of a tool for working out first and last IP address, netmask, and a
> few other things from a subnet definition.
>
> On the old system, it works fine. On the new system, I get the following
> error:
>
> "PHP Fatal error: Unsupported operand types in
> /var/www/test/common_subnet.inc on line 39"
>
Have you checked the types being operated on? I'm wondering if somehow one
of the object properties you're operating on has changed has changed in
terms of type.
I'd try var_dumping each of the properties ($this->network and
$this->netmask) the line above just to make sure they didn't somehow get
switched to a type that bitwise operators complain about (array, Object.)
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
I want to be able to match if a string is contained within the string I am
evaluating.
I know that if ( $name == "xxjacksonxx"); based on the below would be true.
But I want to be able to say if "jackson" is contained within $name that
it's a match.
I tried the below without success..
Not getting the operand properly..
<?
$name = "xxjacksonxx";
if ( preg_match($name, "jackson")) {
print "true";
} else {
print "false";
}
?>
Thanks!
Jack
--- End Message ---
--- Begin Message ---
Try
If(preg_match("/Jackson/i", $name))
{echo 'match'; }else{ echo 'fail'; }
Richard Buskirk
Sent from my iPhone
On Mar 15, 2011, at 1:02 AM, "Jack" <[email protected]> wrote:
> I want to be able to match if a string is contained within the string I am
> evaluating.
>
>
>
> I know that if ( $name == "xxjacksonxx"); based on the below would be true.
>
> But I want to be able to say if "jackson" is contained within $name that
> it's a match.
>
>
>
> I tried the below without success..
>
> Not getting the operand properly..
>
>
>
> <?
>
>
>
> $name = "xxjacksonxx";
>
>
>
> if ( preg_match($name, "jackson")) {
>
> print "true";
>
>
>
> } else {
>
>
>
> print "false";
>
> }
>
>
>
> ?>
>
>
>
> Thanks!
>
> Jack
>
>
>
--- End Message ---
--- Begin Message ---
On 15/03/2011, at 6:02 PM, Jack wrote:
> I want to be able to match if a string is contained within the string I am
> evaluating.
>
>
>
> I know that if ( $name == "xxjacksonxx"); based on the below would be true.
>
> But I want to be able to say if "jackson" is contained within $name that
> it's a match.
>
>
>
> I tried the below without success..
>
> Not getting the operand properly..
>
>
>
> <?
>
>
>
> $name = "xxjacksonxx";
>
>
>
> if ( preg_match($name, "jackson")) {
>
> print "true";
>
>
>
> } else {
>
>
>
> print "false";
>
> }
>
>
>
> ?>
>
>
>
> Thanks!
>
> Jack
if(strpos($name, 'jackson') !== false) {
true
}
You can use stripos for case-insentive matching.
Using regex functions when you don't need the power is overkill and slower.
Your call to preg_match wasn't working because you need your search term first,
and it needs proper delimiters.
---
Simon Welsh
Admin of http://simon.geek.nz/
Who said Microsoft never created a bug-free program? The blue screen never,
ever crashes!
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
--- End Message ---
--- Begin Message ---
Thanks everyone... great examples...works.... ( both methods )
Thanks!
Jack
> -----Original Message-----
> From: Alexis Antonakis [mailto:[email protected]]
> Sent: Tuesday, March 15, 2011 1:10 AM
> To: Jack
> Subject: Re: [PHP] problem with if and exact match
>
> http://php.net/manual/en/function.preg-match.php
>
> On 14/03/11 23:02, Jack wrote:
> > I want to be able to match if a string is contained within the string
> > I am evaluating.
> >
> >
> >
> > I know that if ( $name == "xxjacksonxx"); based on the below would be
> true.
> >
> > But I want to be able to say if "jackson" is contained within $name
> > that it's a match.
> >
> >
> >
> > I tried the below without success..
> >
> > Not getting the operand properly..
> >
> >
> >
> > <?
> >
> >
> >
> > $name = "xxjacksonxx";
> >
> >
> >
> > if ( preg_match($name, "jackson")) {
> >
> > print "true";
> >
> >
> >
> > } else {
> >
> >
> >
> > print "false";
> >
> > }
> >
> >
> >
> > ?>
> >
> >
> >
> > Thanks!
> >
> > Jack
> >
> >
> >
> >
--- End Message ---
--- Begin Message ---
strpos example is much faster though ....
On Tue, Mar 15, 2011 at 7:20 AM, Jack <[email protected]> wrote:
> Thanks everyone... great examples...works.... ( both methods )
>
> Thanks!
> Jack
>
> > -----Original Message-----
> > From: Alexis Antonakis [mailto:[email protected]]
> > Sent: Tuesday, March 15, 2011 1:10 AM
> > To: Jack
> > Subject: Re: [PHP] problem with if and exact match
> >
> > http://php.net/manual/en/function.preg-match.php
> >
> > On 14/03/11 23:02, Jack wrote:
> > > I want to be able to match if a string is contained within the string
> > > I am evaluating.
> > >
> > >
> > >
> > > I know that if ( $name == "xxjacksonxx"); based on the below would be
> > true.
> > >
> > > But I want to be able to say if "jackson" is contained within $name
> > > that it's a match.
> > >
> > >
> > >
> > > I tried the below without success..
> > >
> > > Not getting the operand properly..
> > >
> > >
> > >
> > > <?
> > >
> > >
> > >
> > > $name = "xxjacksonxx";
> > >
> > >
> > >
> > > if ( preg_match($name, "jackson")) {
> > >
> > > print "true";
> > >
> > >
> > >
> > > } else {
> > >
> > >
> > >
> > > print "false";
> > >
> > > }
> > >
> > >
> > >
> > > ?>
> > >
> > >
> > >
> > > Thanks!
> > >
> > > Jack
> > >
> > >
> > >
> > >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---